Unit Testing Angular Service that uses $timeout with Jasmine's Mock Clock

后端 未结 2 1057
情话喂你
情话喂你 2020-12-29 18:18

I have a function inside one of my angular services that I\'d like to be called repeatedly at a regular interval. I\'d like to do this using $timeout. It looks something l

2条回答
  •  执念已碎
    2020-12-29 19:05

    Do not make your test Async by using Jasmine's clock. Instead, use $timeout.flush() to synchronously maintain the flow of the test. It may be a bit tricky to setup, but once you get it then your tests will be faster and more controlled.

    Here's an example of a test that does it using this approach: https://github.com/angular/angular.js/blob/master/test/ngAnimate/animateSpec.js#L618

提交回复
热议问题