QUnit.on()

version added: 2.2

QUnit.on( eventName, callback )

Register a callback to fire whenever the specified event is emitted. Conforms to the js-reporters standard.

Use this to listen for events related to the test suite’s execution. Available event names and corresponding data payloads are defined in the js-reporters specification.

NOTE: The QUnit.on() callback does not handle promises and MUST be synchronous.

parameter description
eventName (string) The name of the event for which to execute the provided callback.
callback (function) Callback to execute. Receives a single argument representing the data for the event.

Examples

Printing results of a test suite.

QUnit.on( "runEnd", runEnd => {
  console.log( `Passed: ${runEnd.passed}` );
  console.log( `Failed: ${runEnd.failed}` );
  console.log( `Skipped: ${runEnd.skipped}` );
  console.log( `Todo: ${runEnd.todo}` );
  console.log( `Total: ${runEnd.total}` );
} );