admin管理员组文章数量:1415467
As far as my understanding goes from reading the Angular testing docs, calling tick()
flushes both (supported) macro tasks, and micro-task queues within the fakeAsync
block. In which case, under the hood, I assume, calling tick()
will be the same as having some additional calls + calling flushMicrotasks()
.
Question is, is there any case where I should use:
it('should pass', fakeAsync(() => {
// given some setup...
doSomethingAsynchronous();
flushMicrotasks();
// do some assertions...
}));
instead of
it('should pass', fakeAsync(() => {
// given some setup...
doSomethingAsynchronous();
tick();
// do some assertions...
}));
❓
As far as my understanding goes from reading the Angular testing docs, calling tick()
flushes both (supported) macro tasks, and micro-task queues within the fakeAsync
block. In which case, under the hood, I assume, calling tick()
will be the same as having some additional calls + calling flushMicrotasks()
.
Question is, is there any case where I should use:
it('should pass', fakeAsync(() => {
// given some setup...
doSomethingAsynchronous();
flushMicrotasks();
// do some assertions...
}));
instead of
it('should pass', fakeAsync(() => {
// given some setup...
doSomethingAsynchronous();
tick();
// do some assertions...
}));
❓
Share Improve this question edited Sep 17, 2018 at 7:06 Glenn Mohammad asked Sep 16, 2018 at 22:41 Glenn MohammadGlenn Mohammad 4,8256 gold badges45 silver badges52 bronze badges1 Answer
Reset to default 5Excerpt from the article here.
macrotasks are enqueued by setTimeout, setInterval, setImmediate, etc. microtasks by process.nextTick, Promises, MutationObserver, etc.
So if you are using setTimeouts, setInterval etc then use tick() and if you are using some promises, then you can use either tick() or flushMicrotasks().
本文标签: javascriptAngular testing tick vs flushMicrotasks in fakeAsync blockStack Overflow
版权声明:本文标题:javascript - Angular testing: tick vs flushMicrotasks in fakeAsync block - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745161223a2645448.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论