Skip to content

Instantly share code, notes, and snippets.

@machty
Created Sep 29, 2016
Embed
What would you like to do?
export default Component.extend({
fooValue: 0,
looper: task(function * () {
while(true) {
yield timeout(500, "x-foo#looper-tick");
this.incrementProperty('fooValue');
}
}).on('init')
})
test('x-foo', function(assert) => {
visit('/');
return waitForTimer("x-foo#looper-tick").then((timer) => {
assert.equal(find('.fooValue').text(), 0);
return timer.fire();
}).then(() => {
assert.equal(find('.fooValue').text(), 1);
});
});
@sukima
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 () {
  this.clock.restore();
});

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