Instantly share code, notes, and snippets.

@machty /e-c-testing.js Secret
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);
});
});
@morhook

This comment has been minimized.

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.

@viniciussbs

This comment has been minimized.

viniciussbs commented Mar 4, 2018

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);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment