What do jasmine runs and waitsFor actually do?

后端 未结 3 1795
渐次进展
渐次进展 2021-01-01 12:56

I use jasmine runs and wait to test asynchronous operations. Everything works fine but I\'m not quite sure what goes on behind the scenes.

The jasmine documentation

3条回答
  •  鱼传尺愫
    2021-01-01 13:42

    From the site: http://www.htmlgoodies.com/beyond/javascript/test-asynchronous-methods-using-the-jasmine-runs-and-waitfor-methods.html#fbid=mzNDUVfhFXg

    Jasmine will call the runs() and waitsFor() methods in the order you passed them. As soon as the JS parser gets to a waitsFor() method it will poll it until it returns true and only then will it continue onto the next runs() method.

    Essentially, the runs() and waitsFor() functions stuff an array with their provided functions. The array is then processed by jamine wherein the functions are invoked sequentially. Those functions registered by runs() are expected to perform actual work while those registered by waitsFor() are expected to be 'latch' functions and will be polled (invoked) every 10ms until they return true or the optional registered timeout period expires. If the timeout period expires an error is reported using the optional registered error message; otherwise, the process continues with the next function in the array. Presumably, expects within the runs() can also trigger a failure report (and perhaps even in the latch functions themselves).

    The documentation is particularly obtuse on these asynchronous features.

提交回复
热议问题