QUnit.on( eventName, callback )

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

QUnit.on() allows you 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.

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.

NOTE: Callback in QUnit.on() does not handle promises and must be synchronous.


Printing results of a test suite.

QUnit.on( "runEnd", function( data ) {
  console.log( "Passed: " + data.testCounts.passed );
  console.log( "Failed: " + data.testCounts.failed );
  console.log( "Skipped: " + data.testCounts.skipped );
  console.log( "Todo: " + data.testCounts.todo );
  console.log( "Total: " + data.testCounts.total );
} );

Using modern syntax:

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