Hide successful tests in QUnit

Jun 3, 2010 · Follow on Twitter and Mastodon javascripttesting

I’m using QUnit as test framework for my JavaScript development. It’s not as nice as NUnit is for .NET or SimpleTest for PHP, but it’s easy to get started with.

However, QUnit lists all tests, not just failing ones. With just a few tests, that looks like this:

QUnit - Full test report

QUnit lists all executed tests by default, even the ones that are successfully executed.

This report only includes 14 tests. Imagine having a hundred tests - it would become unmanagable. I’d prefer to only see failing tests by default.

To fix this, I devided to hack jQuery a bit (applies to jQuery 1.4.2):

  • Open qunit.js.
  • Find the block that begins with var li = document.createElement("li");.
  • Wrap the entire block in if (bad) { ... }.

This makes QUnit only append “bad” tests to the list, which makes the result look like this:

QUnit - Compact test result presentation

If you know of a built-in way to make QUnit behave like this, leave a comment below.

Discussions & More

Please share any ideas, feedback or comments you may have in the Disqus section below, or by replying on Twitter or Mastodon.

If you found this text interesting, make sure to follow me on Twitter and Mastodon for more content like this, and to be notified when new content is published.

If you like & want to support my work, please consider sponsoring me on GitHub Sponsors.