Skip to content

Instantly share code, notes, and snippets.

Created September 29, 2016 16:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save machty/574457b1f2d993cc5959a1d6d6c74e5b to your computer and use it in GitHub Desktop.
Save machty/574457b1f2d993cc5959a1d6d6c74e5b to your computer and use it in GitHub Desktop.
export default Component.extend({
fooValue: 0,
looper: task(function * () {
while(true) {
yield timeout(500, "x-foo#looper-tick");
test('x-foo', function(assert) => {
return waitForTimer("x-foo#looper-tick").then((timer) => {
assert.equal(find('.fooValue').text(), 0);
}).then(() => {
assert.equal(find('.fooValue').text(), 1);
Copy link

morhook commented Jan 12, 2018

I think another possible approach might be with bending-time solutions. Kind of with a special mode where the concurrency tasks can be controlled with a fake-timer, but the internal ember loop-timers can be executed to run correctly the visit, click, etc.

Copy link

Considering your example, could I use async/await?

test('x-foo', async function(assert) => {

  let timer = await waitForTimer("x-foo#looper-tick");

  assert.equal(find('.fooValue').text(), 0);
  assert.equal(find('.fooValue').text(), 1);

Copy link

sukima commented Apr 6, 2022

Adding to the thread. the following worked for me. Caveat: I used sinon.useFakeTimers during unit/integration testing and left as is during acceptance tests.

// Alternative to ember-concurrency's timeout which does not register test
// waiters (settled). Use this for polling tasks to avoid hung acceptance tests
const optOutSettledTimeout = (delay) => new Promise((r) => setTimeout(r, delay));
hooks.beforeEach(function () {
  this.clock = sinon.useFakeTimers();

hooks.afterEach(function () {

test('…', async function (assert) {
  await this.clock.nextAsync();

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment