javascript - Angular testing: tick vs flushMicrotasks in fakeAsync block - Stack Overflow

As far as my understanding goes from reading the Angular testing docs, calling tick() flushes both (sup

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 badges
Add a ment  | 

1 Answer 1

Reset to default 5

Excerpt 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().

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745161224a4614398.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信