Skip to content

Commit

Permalink
Test that t.snapshot.skip() prevents updating snapshots
Browse files Browse the repository at this point in the history
  • Loading branch information
ninevra committed Dec 15, 2020
1 parent 9f2be0d commit 2bf983f
Show file tree
Hide file tree
Showing 6 changed files with 56 additions and 0 deletions.
10 changes: 10 additions & 0 deletions test/snapshot-updates/fixtures/contains-skip-assertion.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
const test = require('ava');

test('always failing snapshot', t => {
t.snapshot(Date.now());
});

test('skipped assertion', t => {
t.snapshot.skip(Date.now()); // eslint-disable-line ava/no-skip-assert
t.pass();
});
11 changes: 11 additions & 0 deletions test/snapshot-updates/fixtures/contains-skip-assertion.js.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# Snapshot report for `contains-skip-assertion.js`

The actual snapshot is saved in `contains-skip-assertion.js.snap`.

Generated by [AVA](https://avajs.dev).

## always failing snapshot

> Snapshot 1
1607992742963
Binary file not shown.
28 changes: 28 additions & 0 deletions test/snapshot-updates/snapshots/test.js.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,3 +66,31 @@ Generated by [AVA](https://avajs.dev).
> Snapshot 1
'Snapshots cannot be updated when selecting specific tests by their line number.'

## cannot update snapshots when skipping snapshot assertions

> failed tests
[
{
file: 'contains-skip-assertion.js',
title: 'skipped assertion',
},
]

> passed tests
[
{
file: 'contains-skip-assertion.js',
title: 'always failing snapshot',
},
]

> files where snapshots could not be updated
[
{
file: 'contains-skip-assertion.js',
},
]
Binary file modified test/snapshot-updates/snapshots/test.js.snap
Binary file not shown.
7 changes: 7 additions & 0 deletions test/snapshot-updates/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,10 @@ test('cannot update snapshots when selecting tests by line number', async t => {
const result = await t.throwsAsync(exec.fixture(['contains-skip.js:4', '-u']));
t.snapshot(exec.cleanOutput(result.stderr));
});

test('cannot update snapshots when skipping snapshot assertions', async t => {
const result = await t.throwsAsync(exec.fixture(['contains-skip-assertion.js', '-u']));
t.snapshot(result.stats.failed, 'failed tests');
t.snapshot(result.stats.passed, 'passed tests');
t.snapshot(result.stats.unsavedSnapshots, 'files where snapshots could not be updated');
});

0 comments on commit 2bf983f

Please sign in to comment.