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:

https://github.com/emberjs/ember-test-helpers/blob/3f34686c527b691cf787037bc7dabb24b2fbdde2/addon-test-support/%40ember/test-helpers/setup-application-context.js#L19

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)

Most upvoted comments

summary of this issue:

  1. setApplication() stuff is not documented, fixed by https://github.com/emberjs/ember-qunit/pull/320

  2. docs for ember-mocha are missing, fixed by https://github.com/emberjs/ember-mocha/pull/200

  3. support for new testing APIs in ember-cli-mirage, fixed by https://github.com/samselikoff/ember-cli-mirage/pull/1263

I’m closing this issue now since all of the mentioned issues have been addressed.

I’m fairly certain that your application is not use setApplication in 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…