question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

assert.throws fails in component integration tests with ember 2.12

See original GitHub issue

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.

npm install -g ember-cli@2.12
ember new ember-test
cd ember-test
ember g component dummy-component
...copy/paste code below...
ember test

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.hbs

{{value}}
{{yield}}

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

Error:

not ok 7 PhantomJS 2.1 - Integration | Component | dummy component: it throws
    ---
        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' }
    ...

Also asked here http://stackoverflow.com/questions/42978212/ember-qunit-assert-throws-does-not-work

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Reactions:2
  • Comments:6 (2 by maintainers)

github_iconTop GitHub Comments

3reactions
sergprouacommented, Mar 23, 2017

workarounds/solutions by @workmanw:

  1. use addon ember-qunit-assert-helpers
  2. this little helper
test('it throws', function (assert) {
  expectEmberAssert(assert, () => {
    this.render(hbs`{{dummy-component}}`);
  }, 'Someone forgot to provide a required value attribute');
});
Read more comments on GitHub >

github_iconTop Results From Across the Web

Ember qunit assert.throws does not work - Stack Overflow
I installed Ember 2.12 and created new project with a component and a test to ensure it throws an error if required attribute...
Read more >
Qunit assert throws not working - Ember.JS
There's a workaround on the issue in Github located here you might try: assert.throws fails in component integration tests with ember 2.12 ......
Read more >
How to Test Ember Components
Pass data in and assert against the rendered HTML; Verify the integration of actions with the components surrounding context. While they are not...
Read more >
ember-qunit | Yarn - Package Manager
ember -qunit simplifies testing of Ember applications with QUnit by providing QUnit-specific wrappers around the helpers contained in ember-test-helpers.
Read more >
[Solved]-Test for throwing Errors in Ember.js-ember.js
test ('my-component should throw an error', function(assert) { assert.expect(1); assert.throws(() => { this.render(hbs`{{my-component myVariable="XYZ"}}`); } ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found