2

I installed Ember 2.12 and created new project with a component and a test to ensure it throws an error if required attribute is not provided. I can't get this test to pass.

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

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

Test fails with the following:

    ---
        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
SergPro
  • 23
  • 1
  • 4
  • also opened a ticket and posted few workaround here https://github.com/emberjs/ember-qunit/issues/256 – SergPro Mar 23 '17 at 15:17
  • nearly the same question: http://stackoverflow.com/questions/42781085/ember-render-hbs-swallowing-thrown-error – ykaragol Mar 23 '17 at 19:11
  • I've filled an issue in ember.js: https://github.com/emberjs/ember.js/issues/15013 – ykaragol Mar 23 '17 at 19:13
  • Possible duplicate of [ember render hbs swallowing thrown error](http://stackoverflow.com/questions/42781085/ember-render-hbs-swallowing-thrown-error) – feanor07 Mar 30 '17 at 16:49

1 Answers1

3

A workaround solution is already provided in github issue submitted; but I am copying steps to apply in order to tackle the issue so as to help others:

Install ember-qunit-assert-helpers via

ember install ember-qunit-assert-helpers

Change your code that throws an error to Ember.assert.

In your test class, use assert.expectAssertion instead of assert.throws.

feanor07
  • 3,328
  • 15
  • 27