Constimport test from 'node:test';
import { expect } from 'bupkis';
test('renders user profile', (t) => {
const profile = { name: 'Alice', age: 30, role: 'admin' };
expect(profile, 'to match snapshot', t);
});
test('redacts passwords', (t) => {
const user = {
username: 'alice',
password: 'secret123',
email: 'alice@example.com',
};
expect(user, 'to match snapshot', t, {
serializer: (value: any) => {
return JSON.stringify(
{
...value,
password: '[REDACTED]',
},
null,
2,
);
},
});
});
test('captures workflow steps', (t) => {
const initial = { status: 'pending' };
expect(initial, 'to match snapshot', t, { hint: 'initial-state' });
const processing = { status: 'processing', progress: 50 };
expect(processing, 'to match snapshot', t, {
hint: 'processing-state',
});
const complete = { status: 'complete', result: 'success' };
expect(complete, 'to match snapshot', t, { hint: 'complete-state' });
});
Asserts that a value matches a stored snapshot.
This assertion provides unified snapshot testing across multiple test frameworks. It automatically detects the test framework from the context parameter and uses the appropriate snapshot mechanism.
Supported Frameworks:
assert.snapshot()supportBasic Usage:
With Custom Serializer:
Multiple Snapshots Per Test:
Mocha Usage:
Explicit Snapshot Names:
Chaining with Other Assertions:
Updating Snapshots: