ember-test-helpers: `click()` helper is not reliable

// in my new ember acceptance tests

await click('[data-test-username-button]');

assert.equal(currentURL(), '/izelnakri'); // this doesn't pass!

click helper doesnt wait for url transition. It could be either due to fact that ember click selector ignore attribute selectors [data-test-username-button] or its waiter is simply buggy.

Unfortunately I already removed a branch in my project where I was refactoring my application tests one by one to new ember application test/qunit modules. I succeeded with unit + integration tests but failed on application tests.

About this issue

  • Original URL
  • State: closed
  • Created 6 years ago
  • Comments: 17 (10 by maintainers)

Most upvoted comments

I will add my two cents here, however, I believe this is more of a problem with settled() than it is click.

I have a link-to component which transitions routes, and the click (settled) is returning control to the test between model and afterModel.

I tried to create an ember-twiddle to show my problem, however, twiddle is not properly loading the visit function from @ember/test-helpers

templates/my-route.hbs

{{#link-to "failing-route" class="failing-route-link"}}

routes/failing-route/view.js

model() {
  const myModel = {};
  return new EmberPromise((resolve) => {
    setTimeout(() => { resolve(model); }, 1);
  });
}

afterModel() {
  // Do stuff in after model
}

tests/acceptance/failing-route-test.js

test('transition to failing route', async function(assert) {
  await visit('/my-route');
  await click('.failing-route-link');
  assert.equal(currentRouteName(), 'failing-route.view', 'Should be at the failing route'); // This fails with currentRouteName return 'failing-route.loading'
});

If I change the model hook to return the model directly, or return Promise.resolve(model) the test passes. Otherwise, it fails.

You people still have this issue? @Turbo87 @rwjblue the Ember Twiddle posted by @raphaelns-developer reproduces the issue.

@viniciussbs the linked twiddle does not seem to reproduce it for me 🤔

@ggayowsky in your snippet you’re never resolving the returned promise

@all since this appears to be solved with the most recent releases I’ll close this as solved. if you run into this issue, please make sure you don’t have @ember/test-helpers locked to an older version.