Same test, different emberjs versions, on [email protected] this "tests" would pass but recently upgraded to [email protected] and now the "test" is failing.
Previously [email protected]
Currently [email protected]
[email protected]
[email protected]
e.g test module
import { module, test } from 'qunit';
import { setupTest } from 'ember-qunit';
module('Unit | Component | foo', function(hooks) {
setupTest(hooks);
hooks.beforeEach(function() {
this.componentFactory = this.owner.factoryFor('component:foo');
});
test('it throws', function(assert) {
assert.expect(1);
assert.throws(
() => {
this.componentFactory.create({
fooBar: null
});
},
/fooBar should not be empty/
);
});
});
...
didReceiveAttrs() {
this._super(...arguments);
assert('fooBar should not be empty', isPresent(this.get('fooBar')));
}
Same test different emberjs versions, on [email protected] this "tests" would pass but recently upgrade to [email protected] and now the "test" is failing.
The solution was to trigger the desirable hook (didReceiveAttrs) with in assert.throw:
e.g
...
test('it throws', function(assert) {
assert.expect(1);
assert.throws(
() => {
this.componentFactory.create({
fooBar: null
}).trigger('didReceiveAttrs');
},
/fooBar should not be empty/
);
});
@mades-g thanks for the code examples, the next step will be create a working reproduction of the issue, perhaps we can make with with ember-twiddle.com
@mades-g I don't think this is a bug in Ember, however I think the way you test for the failure may need to change. I'll post an attempt to test it.
@mades-g See this test https://github.com/ember-triage/issues-17534/blob/master/tests/unit/components/x-foo-test.js#L7-L17
test('didReceiveAttrs throws', function(assert) {
let component = this.owner.factoryFor('component:x-foo').create();
assert.ok(component);
assert.throws(
() => {
component.didReceiveAttrs();
},
/fooBar should not be empty/
);
});
@pixelhandler Thanks for the feed back, the test type for this specific issue, is unit, and you are doing an integration test, and that's probably leveraging from setupRenderingTest and creates the right connect for the assertion.
Maybe my test should be changed to an integration, I was more concerned why it was passing before and due to recent ember-source upgrade now it's failing, but no worries on that, I'm quite new to ember so do mind my mistakes and let me know.
Edit: Just saw your comment comment, I know what you did works, but I wonder why it was passing in 3.1.2 馃
didReceiveAttrs used to be called from inside the constructor, and now it isn鈥檛. The change was done intentionally (and helped with other overall objectives), so I doubt we鈥檇 want to revert...
In general it鈥檚 best to test rendering related things by _actually_ rendering (e.g. setupRenderingTest).
Cheers for the clarification everyone.
I will close this.
I ran into this issue too, and was wondering what's going on. Thanks for clarifying @rwjblue. I saw https://github.com/emberjs/ember.js/commit/2cd6e2f6d570d2489322e317adcb52a0756372d3#diff-7536fca9f7b528326424427194fd9ac2 explains the rationale.