2
我安裝了Ember 2.12並創建了一個帶有組件和測試的新項目,以確保它在未提供必需屬性時會拋出錯誤。我無法通過此測試。Ember qunit assert.throws不起作用
虛設component.hbs
{{value}}
{{yield}}
虛設component.js
import Ember from 'ember';
export default Ember.Component.extend({
value: Ember.computed(() => {
Ember.assert("Someone forgot to provide a required value attribute");
})
});
虛設組分-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: > [email protected]://localhost:7357/assets/test-support.js:7664:49 [email protected]://localhost:7357/assets/vendor.js:50288:22 [email protected]://localhost:7357/assets/vendor.js:28557:23 [email protected]://localhost:7357/assets/vendor.js:10921:14 [email protected]://localhost:7357/assets/vendor.js:10977:15 [email protected]://localhost:7357/assets/vendor.js:11101:20 [email protected]://localhost:7357/assets/vendor.js:11171:28 [email protected]://localhost:7357/assets/vendor.js:11285:19 [email protected]://localhost:7357/assets/vendor.js:33262:32 [email protected]://localhost:7357/assets/test-support.js:8538:30 http://localhost:7357/assets/tests.js:129:19 [email protected]://localhost:7357/assets/test-support.js:4609:17 http://localhost:7357/assets/tests.js:128:18 [email protected]://localhost:7357/assets/test-support.js:3696:34 [email protected]://localhost:7357/assets/test-support.js:3682:13 http://localhost:7357/assets/test-support.js:3860:15 [email protected]://localhost:7357/assets/test-support.js:5094:26 [email protected]://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' } ...個
整個過程的時間不到5分鐘
npm install -g ember-cli
ember new ember-test
ember g component dummy-component
<copy.paste> template, js and the test
ember test
也打開了一張票,並在這裏發佈了幾個解決方法https://github.com/emberjs/ember-qunit/issues/256 – SergPro
幾乎相同的問題:http://stackoverflow.com/questions/42781085/ember-render -hbs-swallowing-thrown-error – ykaragol
我在ember.js中填充了一個問題:https://github.com/emberjs/ember.js/issues/15013 – ykaragol