What do jasmine runs and waitsFor actually do?

后端 未结 3 1777
渐次进展
渐次进展 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:18

    waitsFor does block until the conditions it's waiting for are met or it times out.

    From the jasmine docs: "waitsFor() provides a better interface for pausing your spec until some other work has completed. Jasmine will wait until the provided function returns true before continuing with the next block.".

    The linked docs also have a slightly clearer example or waitsFor.

    EDIT: Ah I see what you mean now. waitsFor won't block JS that isn't wrapped in runs, waitsFor, ect.

    What jasmine is doing is taking the function passed to it via runs or waitsFor and if jasmine is not currently waiting, it executes the function immediately. If it is waiting, it doesn't call it until it's finished waiting.

    That doesn't stop the console.log as it's been passed to jasmine so jasmine can't prevent it from being executed straight away.

提交回复
热议问题