Two new QUnit Test Types – Skipped and Interactive
I love unit testing, and the confident feeling I get from my code being “all green”. But sometimes there are tests that need to be skipped for a bit, perhaps due to a failing backend service or an in-progress refactoring. The easiest solution is to comment them out, but then it’s easy to forget they are being skipped. Instead, I simply added a new test type – testSkip
– to QUnit using the following code. Now when the test is skipped we see it marked as SKIPPED in the QUnit results.
QUnit.testSkip = function() { q.test(arguments[0] + " (SKIPPED)", function() {}); };
I use a similar approach for QUnit tests that involve user interaction. I run lots of tests when coding, but the interactive ones get in the way of my flow. So I have added the test type testManual
which allows me to run them explicitly by simply adding testmanual
to the URL parameters. A similar approach can be used for other test categories or to target tests to a particular browser.
QUnit.testManual = function() { if(/(\?|&)testmanual($|&|=)/.test(window.location.href)) { q.test.apply(q, arguments); } else { q.testSkip.apply(q, arguments); } };
Related articles
- Introduction To JavaScript Unit Testing (coding.smashingmagazine.com)

Posted on March 12, 2012, in Code and tagged JavaScript, jQuery, OpenSource, QUnit. Bookmark the permalink. Leave a comment.
Leave a comment
Comments 0