Testing Synchronous Callbacks - J Query

When testing code with a lot of callbacks, it happens every once in a while that a test that actually should fail just passes, with the assertions in question never showing up in the test results. When the assertions are in a callback that is never called, the assertions aren’t called either, causing the test to silently pass.


QUnit provides a special assertion to define the number of assertions a test contains.When the test completes without the correct number of assertions, it will fail, no matter what result the other assertions, if any, produced.
Usage is plain and simple; just call expect() at the start of a test, with the number of expected assertions as the only argument:

expect() provides the most value when actually testing callbacks. When all code is running in the scope of the test function, expect() provides no additional value—any error preventing assertions to run would cause the test to fail anyway, because the test runner catches the error and considers the test as failed.

All rights reserved © 2018 Wisdom IT Services India Pvt. Ltd DMCA.com Protection Status

J Query Topics