ConstAsserts 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:
import test from 'node:test';
import { expect } from 'bupkis';
test('component renders correctly', (t) => {
const output = renderComponent();
expect(output, 'to match snapshot', t);
});
With Custom Serializer:
test('redacts sensitive data', (t) => {
const data = { public: 'visible', secret: 'password123' };
expect(data, 'to match snapshot', t, {
serializer: (value: any) =>
JSON.stringify({ ...value, secret: '[REDACTED]' }, null, 2),
});
});
Multiple Snapshots Per Test:
test('multi-step process', (t) => {
const step1 = processStep1();
expect(step1, 'to match snapshot', t, { hint: 'step-1' });
const step2 = processStep2();
expect(step2, 'to match snapshot', t, { hint: 'step-2' });
const step3 = processStep3();
expect(step3, 'to match snapshot', t, { hint: 'step-3' });
});
Mocha Usage:
describe('MyComponent', function () {
it('renders correctly', function () {
const output = renderComponent();
expect(output, 'to match snapshot', this);
});
});
Explicit Snapshot Names:
test('any framework', () => {
const output = renderComponent();
expect(output, 'to match snapshot', 'component-default-state');
});
Chaining with Other Assertions:
test('validates and snapshots', (t) => {
const user = getUserData();
expect(
user,
'to satisfy',
{ name: 'Alice' },
'and',
'to have property',
'email',
'and',
'to match snapshot',
t,
);
});
Updating Snapshots:
# node:test
node --test --test-update-snapshots
# Jest/Vitest (Phase 2)
vitest -u
# Other frameworks
BUPKIS_UPDATE_SNAPSHOTS=1 npm test
import 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 with custom options.
This is an extended version of snapshotAssertion that accepts explicit
options for serialization and snapshot naming via the with options syntax.
import test from 'node:test';
import { expect } from 'bupkis';
test('redacts sensitive fields', (t) => {
const data = { username: 'alice', password: 'secret123' };
expect(data, 'to match snapshot', t, 'with options', {
serializer: (value: any) =>
JSON.stringify({ ...value, password: '[REDACTED]' }, null, 2),
});
});
test('workflow stages', (t) => {
const stage1 = { phase: 'init' };
expect(stage1, 'to match snapshot', t, 'with options', {
hint: 'stage-1',
});
const stage2 = { phase: 'processing' };
expect(stage2, 'to match snapshot', t, 'with options', {
hint: 'stage-2',
});
});
Collection of all snapshot assertions.
Currently contains only the main snapshot assertion, but structured as a collection for consistency with other assertion modules and to allow for future expansion (e.g., inline snapshots, property matchers).