I'm just testing edge cases in hopes of better understanding the code. This isn't likely to be important to anyone's use case.
What happened
If a snapshot has an id that matches a test name, it compares against the first snapshot from that test.
What you expected to happen
This should probably either:
Throw an error, like duplicate test titles do.
Report an error by some other means.
Namespace snapshot ids separately from test names. That would probably require changes to the snapshot binary format.
The existing behavior could be used intentionally, but I can't think of a good reason to do so.
Sample code
const test = require('ava');
test('a name', t => {
t.snapshot('one', 'a snapshot with no id');
t.snapshot('two', {id: 'a name'});
});
This produces:
a name
test.js:5
4: t.snapshot('one', 'a snapshot with no id');
5: t.snapshot('two', {id: 'a name'});
6: });
Did not match snapshot
Difference:
- 'two'
+ 'one'
› test.js:5:5
─
1 test failed
The snapshot report looks like:
# Snapshot report for `test.js`
The actual snapshot is saved in `test.js.snap`.
Generated by [AVA](https://avajs.dev).
## a name
> a snapshot with no id
'one'
Configuration
AVA v3.15.0.
No AVA configuration.
Invoking AVA as npx ava or npx ava --update-snapshots.
What you're trying to do
I'm just testing edge cases in hopes of better understanding the code. This isn't likely to be important to anyone's use case.
What happened
If a snapshot has an id that matches a test name, it compares against the first snapshot from that test.
What you expected to happen
This should probably either:
The existing behavior could be used intentionally, but I can't think of a good reason to do so.
Sample code
This produces:
The snapshot report looks like:
Configuration
AVA v3.15.0.
No AVA configuration.
Invoking AVA as
npx ava
ornpx ava --update-snapshots
.