2

I am writing acceptance tests for my ember app and one of the component take user input and validates credentials after which user can click continue and proceed ahead. The problem I am facing is as soon as tests fill in the input fields, then it clicks on the next button and andThen helper is not inducing sufficient wait or pause because of which test fails as I am setting some property once validation is completed.

Is there a way to induce delay while writing acceptance tests apart from andThen.

Bhavya Bansal
  • 257
  • 1
  • 15
  • In newer ember versions, syntax has changed: https://guides.emberjs.com/release/testing/acceptance/ can you try with the new `await fillIn('.my-input')` and `await click('.my-button')`? sometimes the `await settled()` test helper its nice to wait for timeouts and animations... – ch. vonrohr Aug 08 '18 at 21:53
  • It does not work for me, it does not know about await helper. Is there any specific import needed? – Bhavya Bansal Aug 08 '18 at 22:04

2 Answers2

1

Based on the version of Ember you might be using (any version pre v3.0 according to the guides) the ember-maybe-import-regenerator addon may be the best option. This addon will allow you to use async / await within your app code and test code, which should provide you the alternative from andThen that you require. Ember v3.0 provides test helpers that support async / await.

Here is a GitHubGist that provides further insight: async/await in ember tests

Paul Bishop
  • 170
  • 6
1

I found another way to temporarily pause an Ember Qunit test for a specific timeframe. I needed this in ember-cli 3.10.1 and ember-cli-qunit 4.4.0, which includes ember-test-helpers. I'm already using the new async await click() syntax.

The problem I had was await waitFor() wouldn't work for my test because another addon in my app responded to the await click() event, then took an unknown amount of time to process, then re-rendered, removing content instead of inserting it. The next assert in my code would fail when it ran before the addon re-rendered. What I needed was something much closer to a straightforward setTimeout(), because I didn't have a DOM selector I could pass to await waitFor() since the DOM nodes were actually disappearing instead of being rendered. Here is my workaround:

setTimeout(() => {this.resumeTest()}, 1000); // wait for ember-changeset-validations to update, removing invalid input message
await pauseTest();

This uses setTimeout() with an arrow function to maintain scope and wait 1s, then calls this.resumeTest(). The resumeTest() resolves the await pauseTest() line, resuming the test code after this section. In effect, these two lines amount to a 1s temporary pause in the ember test execution.

This has worked perfectly for my tests where a DOM node or other content is being destroyed, which is the opposite of what await waitFor() can handle.

Be sure to include the pauseTest fn in your import statement:

import { pauseTest } from '@ember/test-helpers';
ChrisN
  • 302
  • 2
  • 9