function

test.aroundEach

function aroundEach(
fn: (runTest: () => Promise<void>, context: TestContext, suite: TestSuite) => unknown,
options?: HookOptions
): void;

Wraps each test in a function. The function does its setup, awaits runTest(), then does its teardown.

runTest() runs the beforeEach hooks, the test, the afterEach hooks and the onTestFinished() callbacks. They run in the async context runTest() is called in, so they see the store of an AsyncLocalStorage whose run() calls it. The promise it returns resolves even if the test fails.

  • The first hook registered is the outermost one, and the hooks of an outer describe() block go around those of an inner one.
  • The hook runs again for each retry and each repeat. It doesn't run for a skipped or todo test.
  • The test fails if the hook throws, or if it finishes without calling runTest(). A second runTest() call rejects.
  • The timeout applies to the time before runTest() is called, and again to the time after its promise resolves. The time in between isn't counted.
@param fn

the function to run around each test

@param options

the timeout in milliseconds. 0 means no timeout

aroundEach(async runTest => {
  await database.transaction(runTest);
});