gpt4 book ai didi

ember.js - Ember qunit assert.throws不起作用

转载 作者:行者123 更新时间:2023-12-02 06:02:10 25 4
gpt4 key购买 nike

我安装了Ember 2.12,并使用组件和测试创建了新项目,以确保如果未提供required属性,它会引发错误。我无法通过这项测试。

虚拟组件

{{value}}
{{yield}}

dummy-component.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');
});

测试失败,并显示以下内容:
    ---        actual: >            false        expected: >            true        stack: >            exception@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            run@http://localhost:7357/assets/vendor.js:11285:19            run@http://localhost:7357/assets/vendor.js:33262:32            render@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            run@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        message: >            Error: Assertion Failed: Someone forgot to provide a required value attribute        Log: |            { type: 'error', text: 'null\n' }    ...

whole process took less than 5 min

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

最佳答案

提交的github issue中已经提供了解决方法;但我正在复制适用的步骤以解决此问题,以帮助其他人:

通过以下方式安装ember-qunit-assert-helpers

ember install ember-qunit-assert-helpers

将您的代码 throws更改为 Ember.assert

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

关于ember.js - Ember qunit assert.throws不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42978212/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com