Writing a qUnit test is fairly straight forward. The syntax is as follows:
It doesn’t work when you have anything that replies on async behaviour (ajax, settimeout, animation ect…).
The output is as follows:
Expected at least one assertion, but none were run - call expect(0) to accept zero assertions.
And then finds an assertion outside the test flow.
Uncaught Error: ok() assertion outside test context
If you want to write an asynchronous test, you will have to stop the test runner and tell it when to continue testing. This is the sytax to do so…
If you don’t like the concept of having to stop the test runner, there’s a shorthand way to write this test.
This has been a primer for writing async tests in qUnit. In a later post, I will show a helper to help simulate ajax calls.