QUnit.log()


QUnit.log( callback )

Description: Register a callback to fire whenever an assertion completes.

  • QUnit.log( callback )

    • callback
      Type: Function( Object details )
      Callback to execute. Provides a single argument with the following properties:
      • result
        Type: Boolean
        The boolean result of an assertion, true means passed, false means failed.
      • actual
        Type: Object
        One side of a comparision assertion. Can be undefined when ok() is used.
      • expected
        Type: Object
        One side of a comparision assertion. Can be undefined when ok() is used.
      • message
        Type: String
        A string description provided by the assertion.
      • source
        Type: String
        The associated stacktrace, either from an exception or pointing to the source of the assertion. Depends on browser support for providing stacktraces, so can be undefined.
      • module
        Type: String
        The test module name of the assertion. If the assertion is not connected to any module, the property's value will be undefined.
      • name
        Type: String
        The test block name of the assertion.
      • runtime
        Type: Number
        The time elapsed in milliseconds since the start of the containing QUnit.test(), including setup.
This is one of several callbacks QUnit provides. Its intended for integration scenarios like PhantomJS or Jenkins.

The properties of the details argument are listed below as options.

Examples:

Register a callback that logs the assertion result and its message

1
2
3
QUnit.log(function( details ) {
console.log( "Log: ", details.result, details.message );
});

Logs the module and test block whenever an assertion fails.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
QUnit.log(function( details ) {
if ( details.result ) {
return;
}
var loc = details.module + ": " + details.name + ": ",
output = "FAILED: " + loc + ( details.message ? details.message + ", " : "" );
if ( details.actual ) {
output += "expected: " + details.expected + ", actual: " + details.actual;
}
if ( details.source ) {
output += ", " + details.source;
}
console.log( output );
});