ember 渲染 hbs 吞咽抛出错误 [英] ember render hbs swallowing thrown error
问题描述
我有一个简单的组件集成测试:
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');
});
component.js 的源码如下:
Source code of component.js is like:
export default Ember.Component.extend({
layout,
init() {
this._super(...arguments);
throw 'my-custom-input component error';
}
}
虽然我的 ember-cli 版本是 2.3.0,但测试通过了.但是,在我将 ember-cli 版本更新到 2.11.1 后,测试没有通过.错误是:
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
为什么 ember 渲染开始吞噬抛出的异常?
Why does ember render start to swallow the thrown exception?
推荐答案
好吧,我不太清楚为什么 Ember 社区决定打破测试的解释;但如果有人需要,这里是修复程序.
Well I am not quite sure why Ember community decided to break the test explained; but here is the fix if anyone needs it.
您需要通过<安装ember-qunit-assert-helpers
ember install ember-qunit-assert-helpers
您需要将 throws
异常的代码更改为 Ember.assert
并且在您的测试类中您只需要使用 assert.expectAssertion
而不是 assert.throws
.
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
.
答案来自以下地址的github问题.
The answer is provided from the github issue at the following address.
这篇关于ember 渲染 hbs 吞咽抛出错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!