Questions tagged [qunit]

QUnit is a JavaScript unit testing framework, used by the jQuery project to test its code and plugins, but capable of testing any generic JavaScript code (both on the client and on the server).

QUnit is a JavaScript unit testing framework, used by the jQuery project to test its code and plugins, but capable of testing any generic JavaScript code (both on the client and on the server). Its home page desribes it as follows:

QUnit is a powerful, easy-to-use JavaScript unit testing framework. It's used by the jQuery, jQuery UI and jQuery Mobile projects and is capable of testing any generic JavaScript code, including itself!

QUnit is especially useful for regression testing: Whenever a bug is reported, write a test that asserts the existence of that particular bug. Then fix it and commit both. Every time you work on the code again, run the tests. If the bug comes up again - a regression - you'll spot it immediately and know how to fix it, because you know what code you just changed.

Having good unit test coverage makes safe refactoring easy and cheap. You can run the tests after each small refactoring step and always know what change broke something.

QUnit is similar to other unit testing frameworks like JUnit, but makes use of the features JavaScript provides and helps with testing code in the browser, eg. with it's stop/start facilities for testing asynchronous code.

References

1100 questions
112
votes
1 answer

QUnit vs Jasmine?

What are the main differences between these two testing frameworks? I am a totally new to Test Driven Development and starting from the very beginning.
Sahat Yalkabov
  • 29,198
  • 40
  • 103
  • 171
59
votes
7 answers

Running JavaScript unit tests headlessly in a Continuous Integration build

I have a webapp build plan running on a Continuous Integration system (Atlassian Bamboo 2.5). I need to incorporate QUnit-based JavaScript unit tests into the build plan so that on each build, the Javascript tests would be run and Bamboo would…
miek
  • 3,426
  • 2
  • 27
  • 30
45
votes
5 answers

Override the Equivalence Comparison in Javascript

Is it possible to override the equivalence comparison in Javascript? The closest I have gotten to a solution is by defining the valueOf function and invoking valueOf with a plus in front of the object. This works. equal(+x == +y, true); But this…
Larry Battle
  • 8,222
  • 4
  • 39
  • 54
42
votes
4 answers

Uncaught Error: Assertion Failed: calling set on destroyed object

working in ember-cli testing. After all tests passed it returns extra two test with errors. Uncaught Error: Assertion Failed: calling set on destroyed object Source : '../dist/assets/vendor.js:13269' this is one unit test configuration import…
Nininea
  • 2,451
  • 4
  • 26
  • 50
42
votes
14 answers

What are some JavaScript unit testing and mocking frameworks you have used?

My main JavaScript framework is jQuery, so I would like my unit test and mocking frameworks to be compatible with that. I'd rather not have to introduce another JavaScript framework. I am currently using QUnit for unit testing and Jack for mocking,…
Elijah Manor
  • 17,603
  • 16
  • 69
  • 79
35
votes
5 answers

Qunit parameterized tests and mocking

I have two questions: Can you have parameterised unit tests in qunit? How do you do mocking with qunit e.g. mocking a getJSON call? Thanks
Noel
32
votes
5 answers

Testing Javascript that Manipulates the DOM

I've been looking into javascript test suites and I have found QUnit to be very interesting. I understand how to test computational code, but... How do you test javascript applications written primarily for DOM manipulation? it seems like testing…
Jiaaro
  • 67,024
  • 38
  • 154
  • 182
31
votes
6 answers

JS - Testing code that uses an IntersectionObserver

I have a (rather poorly written) javascript component in my application that handles infinite scroll pagination, and i'm trying to rewrite it to use the IntersectionObserver, as described here, however i'm having issues in testing it. Is there a way…
Raibaz
  • 7,529
  • 9
  • 39
  • 57
28
votes
2 answers

QUnit Vs. Jasmine and TDD Vs. BDD

I've been looking at two libraries for doing unit tests on the front-end. QUnit - http://qunitjs.com/ Jasmine - http://jasmine.github.io/ Jasmine is clearly more BDD focused than QUnit although I could see doing BDD with QUnit by describing the…
Mims H. Wright
  • 3,029
  • 1
  • 23
  • 29
28
votes
2 answers

QUnit is only running the first test

I can't get QUnit to run any test after the first. To be sure I wasn't doing something weird, I pared down the code to be as basic as possible. test("A", function () { ok(true, "Test A"); }); test("B", function () { ok(true, "Test…
Mims H. Wright
  • 3,029
  • 1
  • 23
  • 29
25
votes
2 answers

How can I use HTML fixtures with Karma test runner using Qunit?

I'm playing with Karma test runner (http://karma-runner.github.io/0.8/index.html) using qunit (http://qunitjs.com). I succesfully created and ran simple tests (100% JavaScript), but now I'm trying to use HTML fixtures in order to test code that…
daveoncode
  • 16,281
  • 13
  • 90
  • 146
25
votes
3 answers

QUnit can't recognize more than one test

I am having a problem with QUNIT, no matter what I seem to do the test suites will only ever recognize one test or module, even though I have multiple one's in the javascript. Any help will be greatly appreciated!