6

I have a simple component integration test:

test('it throws error my-custom-input is called', function(assert) {
    assert.throws(() => {
        this.render(hbs`{{my-custom-input}}`);
    }, /my-custom-input component error/, 'Error must have been thrown');
});

Source code of component.js is like:

export default Ember.Component.extend({
    layout,
    init() {
        this._super(...arguments);
        throw 'my-custom-input component error';
    }
}

While my ember-cli version was 2.3.0, the test was passing. However, after I've updated my ember-cli version to 2.11.1, the test did not pass. The error was:

    actual: >
        false
    expected: >
        true

Why does ember render start to swallow the thrown exception?

Ahmet Emre Kilinc
  • 5,489
  • 12
  • 30
  • 42
  • I prepared a [twiddle](https://ember-twiddle.com/23b50ad0f6a793b117451fa69fc0dd52) to illustrate the case; but surprisingly it works in twiddle. However; when I created a brand new ember application; the test fails as described in the original question. Please check out [project repository](https://github.com/feanor07/ember-component-init-error-swallowed) simply to see the case. I hope someone will benefit from these findings to provide a solution. – feanor07 Mar 15 '17 at 06:45
  • I've filled [an issue](https://github.com/emberjs/ember.js/issues/15013) in ember.js about this. – ykaragol Mar 16 '17 at 06:12

1 Answers1

4

Well I am not quite sure why Ember community decided to break the test explained; but here is the fix if anyone needs it.

You need to install ember-qunit-assert-helpers via

ember install ember-qunit-assert-helpers

You need to change your code that throws an exception to Ember.assert and in your test class you just need to use assert.expectAssertion instead of assert.throws.

The answer is provided from the github issue at the following address.

feanor07
  • 3,328
  • 15
  • 27
  • 1
    Also, the [original pull request](https://github.com/emberjs/ember.js/pull/14898) contains a great deal of relevant discussion, and [this issue](https://github.com/emberjs/ember.js/issues/15013) contains a [twiddle reproduction](https://ember-twiddle.com/47c4cfbb571ac3fa83ab912f605ebc6a?fileTreeShown=false&openFiles=tests.integration.components.i-throw-test.js%2C) and work-around. – nickiaconis Mar 28 '17 at 18:39