Skip to content
This repository has been archived by the owner on Nov 11, 2017. It is now read-only.

Commit

Permalink
Properly expectDeprecation when test parameter is a function
Browse files Browse the repository at this point in the history
`Ember.deprecate` is called with `(message, test, options)`. When
`test` is falsy or a function that evaluates to falsy, the deprecation
is issued.

`expectDeprecation` was correctly evaluating the `test` param when it is
a function, but not pushing the correct result of that function into
`actuals`. This made using `expectDeprecate` fail for a deprecation that used
a test function.

Example:

```
// Ember code
function foo() {
  Ember.deprecate('message', function() { return false; });
}

// test code -- this test would erroneously fail because
// expectDeprecation pushes ['message', function() { return false; }]
// onto actuals instead of ['message', false]
expectDeprecation(function() {
  foo();
}, 'message');
```
  • Loading branch information
bantic committed Jun 12, 2015
1 parent 1a1ef3e commit 4007c81
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions addon/test-helper/deprecation.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,12 @@ DeprecationAssert.prototype = {
}
var assertion = this;
this.env.Ember.deprecate = function(msg, test) {
var pushDeprecation = typeof test === 'function' ? !test() : !test;
var resultOfTest = typeof test === 'function' ? test() : test;
var shouldDeprecate = !resultOfTest;

assertion.actuals = assertion.actuals || [];
if (pushDeprecation) {
assertion.actuals.push([msg, test]);
if (shouldDeprecate) {
assertion.actuals.push([msg, resultOfTest]);
}
};
},
Expand Down

0 comments on commit 4007c81

Please sign in to comment.