interface

test.TestContext

interface TestContext

The object passed to test.for() callbacks and to the callbacks of a test made by test.extend(). Each test gets one object, and its hooks receive the same one.

  • readonly expect: Expect

    An expect bound to this test. Its expect.assertions(), expect.hasAssertions() and snapshots belong to this test even when other tests run concurrently.

  • readonly signal: AbortSignal

    Aborted when the test times out.

  • readonly task: TestTask

    The running test.

  • message: string,
    type?: string,
    attachment?: object
    ): Promise<TestAnnotation>;

    Adds an annotation to task.annotations.

    message: string,
    attachment?: object
    ): Promise<TestAnnotation>;
  • fn: (context: TestContext) => void | Promise<unknown>,
    options?: HookOptions
    ): void;

    Like onTestFinished(), but only runs if the test failed.

  • fn: (context: TestContext) => void | Promise<unknown>,
    options?: HookOptions
    ): void;

    Runs fn after the test, its afterEach hooks and its fixture teardown. The last one registered runs first.

  • note?: string
    ): never;

    Stops the test and reports it as skipped.

    condition: boolean,
    note?: string
    ): void;

    Stops the test and reports it as skipped, unless condition is false.