FonTestFinished
Bun

function

test.onTestFinished

function onTestFinished(
fn: () => void | Promise<unknown> | (done: (err?: unknown) => void) => void,
options?: HookOptions
): void;

Runs a function after a test finishes, including after all afterEach hooks.

This is useful for cleanup tasks that need to run at the very end of a test, after all other hooks have completed.

Can only be called inside a test, not in describe blocks.

@param fn

the function to run

test("my test", () => {
  onTestFinished(() => {
    // This runs after all afterEach hooks
    console.log("Test finished!");
  });
});