Skip to content

Commit

Permalink
fix(tests): proper handling of undefined literal value
Browse files Browse the repository at this point in the history
New glimmer engines makes difference between null and undefined values. Note that previous behaviour
was an accident (cf. emberjs/ember.js#14016)
This commit updates tests to reflect that.
Was necessary to add conditional tests depending on the ember version. This version check relies on
the ``ember-version-is`` addon.
  • Loading branch information
Baptiste Meurant committed Sep 9, 2016
1 parent 4c5a752 commit 11b60e9
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 1 deletion.
17 changes: 16 additions & 1 deletion README.md
Expand Up @@ -150,7 +150,22 @@ export default Ember.Route.extend({
{{array-contains model 'Blacksad' property='title'}}
```

Note that null or undefined are considered acceptable and equivalent values for 'value' parameter (resolve both to null)
### ``null`` and ``undefined``

``null`` and ``undefined`` are considered acceptable values for 'value' parameter.

* **until ember 2.8**, ``null`` and ``undefined`` are both coerced to ``null`` by the templating engine. The following
expressions are therefore both leading to check for the presence of a ``null`` value inside the array:

```hbs
{{array-contains collection null}}
{{array-contains collection undefined}}
```

* **ember 2.9 (glimmer)** changed this behaviour. ``undefined`` are then preserved and not coerced to ``null`` anymore.

It could eventually break some apps relying on the initial behaviour but it has been considered as a fix since the first behaviour
was accidental. See [this issue](https://github.com/emberjs/ember.js/issues/14016) for details.

## Changelog

Expand Down
1 change: 1 addition & 0 deletions package.json
Expand Up @@ -51,6 +51,7 @@
"ember-paper": "1.0.0-alpha.3",
"ember-resolver": "^2.0.3",
"ember-runtime-enumerable-includes-polyfill": "^1.0.1",
"ember-version-is": "0.0.3",
"loader.js": "^4.0.11",
"urljs": "2.3.1",
"yuidoc-ember-cli-theme": "Turbo87/yuidoc-ember-cli-theme"
Expand Down
17 changes: 17 additions & 0 deletions tests/integration/helpers/array-contains-test.js
Expand Up @@ -2,6 +2,10 @@ import Ember from 'ember';
import { describeComponent, it } from 'ember-mocha';
import { expect } from 'chai';
import hbs from 'htmlbars-inline-precompile';
import { is } from 'ember-version-is';

// remove alpha, beta, canary, etc. suffixes to the current Ember version
const BASE_VERSION = Ember.VERSION.indexOf('-') === -1 ? Ember.VERSION : Ember.VERSION.substr(0, Ember.VERSION.indexOf('-'));

describeComponent('array-contains', 'helper:array-contains', { integration: true }, function() {

Expand All @@ -25,6 +29,12 @@ describeComponent('array-contains', 'helper:array-contains', { integration: true
it('should return true if literal contained', function () {
this.set('array', ['c', 'string', 0, true, null]);

// before ember 2.9, null and undefined were both coerced to null
// (see https://github.com/emberjs/ember.js/issues/14016)
if (is(BASE_VERSION, "greaterThanOrEqualTo", "2.9.0")) {
this.get('array').push(undefined);
}

this.render(hbs`{{array-contains array 'c'}}`);
expect(this.$().text()).to.equal("true", "array should contain 'c'");

Expand Down Expand Up @@ -58,6 +68,13 @@ describeComponent('array-contains', 'helper:array-contains', { integration: true

this.render(hbs`{{array-contains array false}}`);
expect(this.$().text()).to.equal("false", "array should not contain 'false'");

// before ember 2.9, null and undefined were both coerced to null
// (see https://github.com/emberjs/ember.js/issues/14016)
if (is(BASE_VERSION, "greaterThanOrEqualTo", "2.9.0")) {
this.render(hbs`{{array-contains array undefined}}`);
expect(this.$().text()).to.equal("false", "array should not contain 'undefined'");
}
});

it('should return true if native object contained', function () {
Expand Down

0 comments on commit 11b60e9

Please sign in to comment.