Inline Snapshots with non literal can't be found
See original GitHub issue🐛 Bug Report
When I try to add a test with an inline snapshot:
it('works with inline snapshots', () => {
expect({a: 1}).toMatchInlineSnapshot();
});
I get this error:
Jest: Couldn't locate all inline snapshots.
I can’t repro this in repl.it because that version does not have inline snapshots yet:
TypeError: expect(...).toMatchInlineSnapshot is not a function
I cloned the github repo and added a test to inline_snapshots.test.js
test('saveInlineSnapshots() replaces empty function call with a template literal for objects', () => {
const filename = path.join(__dirname, 'my.test.js');
fs.readFileSync = (jest.fn(
() => `expect({a: 'a'}).toMatchInlineSnapshot();\n`,
): any);
saveInlineSnapshots(
[
{
frame: {column: 11, file: filename, line: 1},
snapshot: `{a: 'a'}`,
},
],
prettier,
babelTraverse,
);
expect(fs.writeFileSync).toHaveBeenCalledWith(
filename,
"expect({a: 'a'}).toMatchInlineSnapshot(`{a: 'a'}`);\n",
);
});
and this reproes the issue:
FAIL packages/jest-snapshot/src/__tests__/inline_snapshots.test.js
✓ saveInlineSnapshots() replaces empty function call with a template literal (67ms)
✕ saveInlineSnapshots() replaces empty function call with a template literal for objects (19ms)
✓ saveInlineSnapshots() replaces existing template literal - babylon parser (4ms)
✓ saveInlineSnapshots() replaces existing template literal - flow parser (2ms)
✓ saveInlineSnapshots() replaces existing template literal - typescript parser (2ms)
✓ saveInlineSnapshots() replaces existing template literal with property matchers (3ms)
✓ saveInlineSnapshots() throws if frame does not match (2ms)
✓ saveInlineSnapshots() throws if multiple calls to to the same location (2ms)
✓ saveInlineSnapshots() uses escaped backticks (2ms)
● saveInlineSnapshots() replaces empty function call with a template literal for objects
Jest: Couldn't locate all inline snapshots.
at Object.parse (packages/jest-snapshot/src/inline_snapshots.js:168:11)
Issue Analytics
- State:
- Created 5 years ago
- Reactions:10
- Comments:25 (11 by maintainers)
Top Results From Across the Web
Inline Snapshots with non literal can't be found - Bountysource
When I try to add a test with an inline snapshot: it('works with inline snapshots', () => { expect({a: 1}).toMatchInlineSnapshot(); });.
Read more >Inline Snapshot Testing - Medium
It's great that we can now record and re-record our snapshots, but now we have a slightly weirder issue: we can't see the...
Read more >Expect - Jest
However, inline snapshot will always try to append to the first argument or the second when the first argument is the property matcher,...
Read more >Groovy Language Documentation
2, When we try to fetch the value with a String key, we will not find it, ... It allows you to inline...
Read more >Markdown Syntax Documentation - Daring Fireball
Inline HTML. Markdown's syntax is intended for one purpose: to be used as a format for writing for the web. Markdown is not...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
What helped for me with Jest 27 and typescript is to add
sourceMap: true
in mytsconfig.json
. It immediately fixed the problem.ts-jest
used to have it on by default, but changed it in v27.@SimenB I don’t have a minimal repro yet. I can reproduce it in react’s codebase though:
Produces
Applying
Fixes the issue.
So it looks like the stack trace is based on the code after transpilation (particularly after
@babel/plugin-transform-shorthand-properties
).