ember-test-helpers: New style tests fail on visit()
I have just upgraded my app to Ember 3, and wanted to try out the new style tests.
So I generated a new, super basic test (ember g acceptance-test new-style), and tried to run it:
import { module, test } from 'qunit';
import { visit, currentURL } from '@ember/test-helpers';
import { setupApplicationTest } from 'ember-qunit';
module('Acceptance | new style', function(hooks) {
setupApplicationTest(hooks);
test('visiting /login', async function(assert) {
await visit('/login');
assert.equal(currentURL(), '/login');
});
});
However, I get the following error:
TypeError: Cannot read property 'apply' of undefined
at setup-application-context.js:27
at tryCatcher (rsvp.js:215)
at invokeCallback (rsvp.js:393)
at publish (rsvp.js:379)
at rsvp.js:10
at invoke (backburner.js:205)
at Queue.flush (backburner.js:125)
at DeferredActionQueues.flush (backburner.js:278)
at Backburner.end (backburner.js:410)
at Backburner._boundAutorunEnd (backburner.js:372)
After some debugging, the problem seems to be that in the setup-application-context.js, in this line:
owner doesn’t seem to have a visit method. When I look at the owner object in the debugger, I see that it only has __container__ and __registry__ properties.
I have updated to all the latest versions of everything, as far as I see:
- ember-cli-qunit: 4.3.1
- ember-qunit: 3.3.1
- @ ember/test-helpers: 0.7.17
- ember-cli: 3.0.0
- ember-source: 3.0.0
- ember-data: 3.0.1
About this issue
- Original URL
- State: closed
- Created 6 years ago
- Comments: 20 (10 by maintainers)
summary of this issue:
setApplication()stuff is not documented, fixed by https://github.com/emberjs/ember-qunit/pull/320docs for
ember-mochaare missing, fixed by https://github.com/emberjs/ember-mocha/pull/200support for new testing APIs in
ember-cli-mirage, fixed by https://github.com/samselikoff/ember-cli-mirage/pull/1263I’m closing this issue now since all of the mentioned issues have been addressed.
I’m fairly certain that your application is not use
setApplicationin its tests/test-helper.js file. This forces us to make a “fake” owner which only has the registry / container interface.We need to add helpful assertions in setup application context when their isn’t an application set…