【问题标题】:Ember qunit assert.throws does not workEmber qunit assert.throws 不起作用
【发布时间】:2017-08-16 03:14:49
【问题描述】:

我安装了 Ember 2.12 并创建了带有组件和测试的新项目,以确保在未提供所需属性时它会引发错误。我不能让这个测试通过。

虚拟组件.hbs

{{value}}
{{yield}}

虚拟组件.js

import Ember from 'ember';
export default Ember.Component.extend({
  value: Ember.computed(() => {
    Ember.assert("Someone forgot to provide a required value attribute");
  })
});

dummy-component-test.js

import { moduleForComponent, test } from 'ember-qunit';
import hbs from 'htmlbars-inline-precompile';

moduleForComponent('dummy-component', 'Integration | Component | dummy component', {
  integration: true
});

test('it throws', function(assert) {
  assert.throws(() => {
    this.render(hbs`{{dummy-component}}`);
  }, 'Error: Assertion Failed: Someone forgot to provide a required value    attribute');
});

测试失败并显示以下内容:

--- 实际:> 错误的 预期:> 真的 堆栈:> 异常@http://localhost:7357/assets/test-support.js:7664:49 adapterDispatch@http://localhost:7357/assets/vendor.js:50288:22 dispatchError@http://localhost:7357/assets/vendor.js:28557:23 invokeWithOnError@http://localhost:7357/assets/vendor.js:10921:14 flush@http://localhost:7357/assets/vendor.js:10977:15 flush@http://localhost:7357/assets/vendor.js:11101:20 end@http://localhost:7357/assets/vendor.js:11171:28 运行@http://localhost:7357/assets/vendor.js:11285:19 运行@http://localhost:7357/assets/vendor.js:33262:32 渲染@http://localhost:7357/assets/test-support.js:8538:30 http://localhost:7357/assets/tests.js:129:19 throws@http://localhost:7357/assets/test-support.js:4609:17 http://localhost:7357/assets/tests.js:128:18 runTest@http://localhost:7357/assets/test-support.js:3696:34 运行@http://localhost:7357/assets/test-support.js:3682:13 http://localhost:7357/assets/test-support.js:3860:15 process@http://localhost:7357/assets/test-support.js:5094:26 begin@http://localhost:7357/assets/test-support.js:5077:11 http://localhost:7357/assets/test-support.js:4294:11 留言:> 错误:断言失败:有人忘记提供必需的值属性 日志:| { 类型:'错误',文本:'null\n' } ...

整个过程不到 5 分钟

npm install -g ember-cli
ember new ember-test
ember g component dummy-component
<copy.paste> template, js and the test
ember test

【问题讨论】:

标签: ember.js ember-cli assert throws ember-qunit


【解决方案1】:

github issue已提交解决方案;但我正在复制申请步骤以解决问题以帮助他人:

通过

安装 ember-qunit-assert-helpers
ember install ember-qunit-assert-helpers

throws 出错的代码更改为Ember.assert

在您的测试类中,使用assert.expectAssertion 而不是assert.throws

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-01-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多