ember render hbs swallowing thrown error

守給你的承諾、 提交于 2019-12-18 16:55:28

问题


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?


回答1:


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.



来源:https://stackoverflow.com/questions/42781085/ember-render-hbs-swallowing-thrown-error

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!