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