ember渲染hbs吞咽抛出错误 [英] ember render hbs swallowing thrown error

查看:140
本文介绍了ember渲染hbs吞咽抛出错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个简单的组件集成测试:

  test('it throws error my-custom-input is called' function(assert){
assert.throws(()=> {
this.render(hbs` {{my-custom-input}}`);
},/ my-自定义输入组件错误/,'错误必须被抛出');
});

component.js的源代码如下:



导出默认值Ember.Component.extend({
layout,
init(){
this._super(... arguments);
throw'my-custom-input component error';
}
}



虽然我的ember-cli版本是2.3.0,但测试已经过去了,但是在将我的ember-cli版本更新到2.11.1之后,测试没有通过,错误是:

 实际:> 
false
期望:>
true

为什么ember渲染开始吞下抛出的异常?

解决方案我不太清楚为什么Ember社区决定打破测试解释;但是如果有人需要,这里是修复。



你需要安装 ember-qunit-as sert-helpers 通过

  ember install ember-qunit-assert-helpers 

您需要将代码 throws 将一个例外更改为 Ember.assert 并且在你的测试类中你只需要使用 assert.expectAssertion 而不是 assert.throws



答案是从github问题在以下地址


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?

解决方案

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.

这篇关于ember渲染hbs吞咽抛出错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆