Function createAssertSnapshot

  • Create assertSnapshot function with the given options.

    The specified option becomes the default for returned assertSnapshot

    Type Parameters

    • T

      The type of the snapshot

    Parameters

    • options: SnapshotOptions<T>

      The options

    • baseAssertSnapshot: {
          <T>(context: TestContext, actual: T, options: SnapshotOptions<T>): Promise<void>;
          <T>(context: TestContext, actual: T, message?: string): Promise<void>;
      } = assertSnapshot

      assertSnapshot function implementation. Default to the original assertSnapshot

        • <T>(context, actual, options): Promise<void>
        • Make an assertion that actual matches a snapshot. If the snapshot and actual do not match, then throw.

          Type parameter can be specified to ensure values under comparison have the same type.

          Type Parameters

          • T

            The type of the snapshot

          Parameters

          • context: TestContext

            The test context

          • actual: T

            The actual value to compare

          • options: SnapshotOptions<T>

            The options

          Returns Promise<void>

          import { assertSnapshot } from "@std/testing/snapshot";

          Deno.test("snapshot", async (t) => {
          await assertSnapshot<number>(t, 2);
          });
        • <T>(context, actual, message?): Promise<void>
        • Make an assertion that actual matches a snapshot. If the snapshot and actual do not match, then throw.

          Type parameter can be specified to ensure values under comparison have the same type.

          Type Parameters

          • T

            The type of the snapshot

          Parameters

          • context: TestContext

            The test context

          • actual: T

            The actual value to compare

          • Optionalmessage: string

            The optional assertion message

          Returns Promise<void>

          import { assertSnapshot } from "@std/testing/snapshot";

          Deno.test("snapshot", async (t) => {
          await assertSnapshot<number>(t, 2);
          });

    Returns typeof assertSnapshot

    assertSnapshot function with the given default options.

    import { createAssertSnapshot } from "@std/testing/snapshot";

    const assertSnapshot = createAssertSnapshot({
    // Uses the custom directory for saving snapshot files.
    dir: "my_snapshot_dir",
    });

    Deno.test("a snapshot test case", async (t) => {
    await assertSnapshot(t, {
    foo: "Hello",
    bar: "World",
    });
    })