Manual:JavaScript unit testing/QUnit guidelines

QUnit comparisons
Use comparing functions such as,   etc. instead of. Providing an explicit expected value serves to self-document the expected result, as well as to allow the test runner to display the difference between the expected and actual values. When using  it forces one to do inline comparisons, which lose this information. This is especially important when working with test reports generated externally (eg. from Jenkins) in which case the test report is all you have.

In cases where the exact value is too variable or doesn't matter, you can still make an explicit comparison by checking its type (in case of a function), or its length (in case of an array or string). For example:

When dealing with objects (such as arrays, object literals, or other objects) one can't use  to compare the content. In such case one has to use  which will loop over the object and compare each key/value separately. For example:

Test elements
The QUnit runner automatically ensures the  element exists and is cleaned by QUnit before each test. Use this for any elements that need to be connected to the document. Avoid appending nodes elsewhere in the document as they may be left behind and affect other tests when a test fails early.