【发布时间】:2020-02-19 03:44:15
【问题描述】:
在 Ember 中,我有一个组件,它启动一个永无止境的轮询以保持一些数据是最新的。像这样:
export default Component.extend({
pollTask: task(function * () {
while(true) {
yield timeout(this.get('pollRate'));
this.fetchSomeData();
}
}).on('init')
})
这会导致预先存在的验收测试卡在此任务中并永远运行,即使它应该异步运行。测试如下:
test('my test', async function(assert) {
mockFindRecord(make('fetched-model'));
await visit('/mypage'); // gets stuck here
await typeIn('input', 'abc123');
assert.ok(somethingAboutThePage);
});
一开始我以为我把请求模拟错了,测试只是超时了,但实际上它是正确地轮询数据。去掉这个任务,验收测试就正常结束了。
手动测试似乎可以正常工作,并且没有任何问题。为什么会发生这种情况?解决这个问题的正确方法是什么?
看到了Unit testing ember-concurrency tasks and yields,但它并没有真正的帮助,因为它只处理单元测试。
【问题讨论】:
标签: ember.js concurrency qunit ember-qunit ember-concurrency