Skip to main content

interface TestContextAssert

extends Pick<assert,
"deepEqual"
| "deepStrictEqual"
| "doesNotMatch"
| "doesNotReject"
| "doesNotThrow"
| "equal"
| "fail"
| "ifError"
| "match"
| "notDeepEqual"
| "notDeepStrictEqual"
| "notEqual"
| "notStrictEqual"
| "ok"
| "partialDeepStrictEqual"
| "rejects"
| "strictEqual"
| "throws"
>

Index Signatures #

#[name: string]: (...args: any[]) => void

Methods #

#fileSnapshot(
value: any,
path: string,
): void

This function serializes value and writes it to the file specified by path.

test('snapshot test with default serialization', (t) => {
  t.assert.fileSnapshot({ value1: 1, value2: 2 }, './snapshots/snapshot.json');
});

This function differs from context.assert.snapshot() in the following ways:

  • The snapshot file path is explicitly provided by the user.
  • Each snapshot file is limited to a single snapshot value.
  • No additional escaping is performed by the test runner.

These differences allow snapshot files to better support features such as syntax highlighting.

#snapshot(
value: any,
): void

This function implements assertions for snapshot testing.

test('snapshot test with default serialization', (t) => {
  t.assert.snapshot({ value1: 1, value2: 2 });
});

test('snapshot test with custom serialization', (t) => {
  t.assert.snapshot({ value3: 3, value4: 4 }, {
    serializers: [(value) => JSON.stringify(value)]
  });
});

Did you find what you needed?

Privacy policy