Skip to content
This repository has been archived by the owner on Apr 1, 2024. It is now read-only.

Latest commit

 

History

History
39 lines (29 loc) · 1.22 KB

hooks.md

File metadata and controls

39 lines (29 loc) · 1.22 KB
layout title excerpt groups redirect_from version_added
page-api
QUnit.hooks
Add global callbacks to run before or after each test.
extension
/QUnit/hooks/
2.18.0

QUnit.hooks.beforeEach( callback )
QUnit.hooks.afterEach( callback )

Register a global callback to run before or after each test.

parameter description
callback (function) Callback to execute. Called with an assert argument.

This is the equivalent of applying a QUnit.module() hook to all modules and all tests, including global tests that are not associated with any module.

Similar to module hooks, global hooks support async functions or returning a Promise, which will be waited for before QUnit continues executing tests. Each global hook also has access to the same assert object and test context as the QUnit.test that the hook is running for.

For more details about hooks, refer to QUnit.module § Hooks.

Examples

QUnit.hooks.beforeEach(function () {
  this.app = new MyApp();
});

QUnit.hooks.afterEach(async function (assert) {
  assert.deepEqual([], await this.app.getErrors(), 'MyApp errors');

  MyApp.reset();
});