Ember qunit assert.throws не работает

Я установил Ember 2.12 и создал новый проект с компонентом и тестом, чтобы убедиться, что он выдает ошибку, если не указан требуемый атрибут. Я не могу пройти этот тест.

dummy-component.hbs

{{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");
  })
});

фиктивный компонент-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' }
    ...

весь процесс занял менее 5 минут

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

person SergPro    schedule 23.03.2017    source источник
comment
также открыл тикет и опубликовал здесь несколько обходных путей github.com/emberjs/ember-qunit/issues / 256   -  person SergPro    schedule 23.03.2017
comment
почти тот же вопрос: stackoverflow.com/questions / 42781085 /   -  person ykaragol    schedule 23.03.2017
comment
Я заполнил проблему в ember.js: github.com/emberjs/ember.js / issues / 15013   -  person ykaragol    schedule 23.03.2017
comment
Возможный дубликат ошибки рендеринга hbs глотания тлеющего угля   -  person feanor07    schedule 30.03.2017


Ответы (1)


Обходное решение уже предоставлено в отправленной проблеме github; но я копирую шаги, которые нужно применить, чтобы решить проблему и помочь другим:

Установите ember-qunit-assert-helpers через

ember install ember-qunit-assert-helpers

Измените код, который throws является ошибкой, на Ember.assert.

В вашем тестовом классе используйте assert.expectAssertion вместо assert.throws.

person feanor07    schedule 24.03.2017