QUnit is a JavaScript unit testing framework. It is used to test projects like jQuery,jQuery UI and jQuery Mobile. It has got strong roots in frontend JavaScript testing and includes some neat features to test DOM operations. That’s why we’re using it for frontend testing in this screencast. QUnit is perfectly capable of testing your node.jsprojects as well, though.
Synchronous callbacks
How do you test that a callback function gets called after you pass it to another function? You can pass an anonymous function containing an assertion as a callback. But then the problem is, even if this assertion never gets executed, the test won’t fail because all other assertions passed. In QUnit, you can tell a test how many assertions should succeed. This way the test will fail if some assertions don’t get executed.
Asynchronous callbacks
But what if a callback is only invoked some time later, after a result came in or after some time passed? The test will probably have finished unsuccessfully by then. QUnit allows tests to wait for asynchronous callbacks to be called.
The screencast contains examples of both, synchronous and asynchronous callbacks. Watch the screencast to learn more!
Your new post is loading...