-
-
Save machty/574457b1f2d993cc5959a1d6d6c74e5b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | |
}); | |
}); |
Considering your example, could I use async
/await
?
test('x-foo', async function(assert) => {
visit('/');
let timer = await waitForTimer("x-foo#looper-tick");
assert.equal(find('.fooValue').text(), 0);
await timer.fire();
assert.equal(find('.fooValue').text(), 1);
});
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
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 thevisit
,click
, etc.