-
-
Notifications
You must be signed in to change notification settings - Fork 6.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[RFC] Inline Snapshots #6380
Merged
Merged
[RFC] Inline Snapshots #6380
Changes from all commits
Commits
Show all changes
34 commits
Select commit
Hold shift + click to select a range
fed959f
[RFC] Inline Snapshots
azz c639484
Fix typechecking and refactor
azz 396b20b
Refactor State#match
azz 2816e7d
Fix stacktrace regression
azz a215e16
Remove unused argument
azz 8c821a1
Fix support for property matchers
azz bbe79ba
Fix tests after State#match refactor
azz d5d349b
Fix toThrowErrorMatchingInlineSnapshot
azz 190df70
Optimize snapshot lookup
azz 05f94df
Support flow parser
azz eb6d86d
Relax prettier version requirement
azz 14b8b90
Fix TypeScript support
azz af1696e
Support toMatchInlineSnapshot from external files
azz 91e3482
Add tests for saveInlineSnapshots()
azz 8334b6f
Fix InlineSnapshot type definition
azz 80f75ee
Escape backtick strings
azz b3f462d
Add test for escaping backticks
azz 8ed6096
Code review fixes
azz c07788a
Support project option for prettier
azz 657f10e
Refactor configuration
azz 97c054a
Fix typechecking
azz 6537c33
Set default value in cli/options
azz 51c42ef
Fix typechecking
azz cc0bcdd
Write E2E tests for toMatchInlineSnapshot
azz 58e6f59
Fix bad copy/paste
azz e1ffa94
Parameterize saveInlineSnapshots test with jest-each
azz 408bad4
Write E2E tests for toThrowErrorMatchingInlineSnapshot
azz 3f6531b
Write more aync tests
azz 8c9a441
Skip currently failing test
azz 52740e1
Remove unused testPath property from State
azz dcbaec8
Write documentation
azz 436cd7f
Support async matchers
azz f653fdf
Fix links in docs
azz 5f89615
Merge branch 'master' into jest-inline-snapshots
azz File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
115 changes: 115 additions & 0 deletions
115
e2e/__tests__/__snapshots__/to_match_inline_snapshot.test.js.snap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,115 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`basic support: initial write 1`] = ` | ||
"test('inline snapshots', () => | ||
expect({apple: 'original value'}).toMatchInlineSnapshot(\` | ||
Object { | ||
\\"apple\\": \\"original value\\", | ||
} | ||
\`)); | ||
" | ||
`; | ||
|
||
exports[`basic support: snapshot mismatch 1`] = ` | ||
"test('inline snapshots', () => | ||
expect({apple: 'updated value'}).toMatchInlineSnapshot(\` | ||
Object { | ||
\\"apple\\": \\"original value\\", | ||
} | ||
\`)); | ||
" | ||
`; | ||
|
||
exports[`basic support: snapshot passed 1`] = ` | ||
"test('inline snapshots', () => | ||
expect({apple: 'original value'}).toMatchInlineSnapshot(\` | ||
Object { | ||
\\"apple\\": \\"original value\\", | ||
} | ||
\`)); | ||
" | ||
`; | ||
|
||
exports[`basic support: snapshot updated 1`] = ` | ||
"test('inline snapshots', () => | ||
expect({apple: 'updated value'}).toMatchInlineSnapshot(\` | ||
Object { | ||
\\"apple\\": \\"updated value\\", | ||
} | ||
\`)); | ||
" | ||
`; | ||
|
||
exports[`handles property matchers: initial write 1`] = ` | ||
"test('handles property matchers', () => { | ||
expect({createdAt: new Date()}).toMatchInlineSnapshot( | ||
{createdAt: expect.any(Date)}, | ||
\` | ||
Object { | ||
\\"createdAt\\": Any<Date>, | ||
} | ||
\`, | ||
); | ||
}); | ||
" | ||
`; | ||
exports[`handles property matchers: snapshot failed 1`] = ` | ||
"test('handles property matchers', () => { | ||
expect({createdAt: \\"string\\"}).toMatchInlineSnapshot( | ||
{createdAt: expect.any(Date)}, | ||
\` | ||
Object { | ||
\\"createdAt\\": Any<Date>, | ||
} | ||
\`, | ||
); | ||
}); | ||
" | ||
`; | ||
exports[`handles property matchers: snapshot passed 1`] = ` | ||
"test('handles property matchers', () => { | ||
expect({createdAt: new Date()}).toMatchInlineSnapshot( | ||
{createdAt: expect.any(Date)}, | ||
\` | ||
Object { | ||
\\"createdAt\\": Any<Date>, | ||
} | ||
\`, | ||
); | ||
}); | ||
" | ||
`; | ||
exports[`handles property matchers: snapshot updated 1`] = ` | ||
"test('handles property matchers', () => { | ||
expect({createdAt: 'string'}).toMatchInlineSnapshot( | ||
{createdAt: expect.any(String)}, | ||
\` | ||
Object { | ||
\\"createdAt\\": Any<String>, | ||
} | ||
\`, | ||
); | ||
}); | ||
" | ||
`; | ||
exports[`supports async matchers 1`] = ` | ||
"test('inline snapshots', async () => { | ||
expect(Promise.resolve('success')).resolves.toMatchInlineSnapshot( | ||
\`\\"success\\"\`, | ||
); | ||
expect(Promise.reject('fail')).rejects.toMatchInlineSnapshot(\`\\"fail\\"\`); | ||
}); | ||
" | ||
`; | ||
exports[`supports async tests 1`] = ` | ||
"test('inline snapshots', async () => { | ||
await 'next tick'; | ||
expect(42).toMatchInlineSnapshot(\`42\`); | ||
}); | ||
" | ||
`; |
28 changes: 28 additions & 0 deletions
28
e2e/__tests__/__snapshots__/to_throw_error_matching_inline_snapshot.test.js.snap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`should support rejecting promises 1`] = ` | ||
"test('should support rejecting promises', async () => { | ||
await expect( | ||
Promise.reject(new Error('octopus')), | ||
).rejects.toThrowErrorMatchingInlineSnapshot(\`\\"octopus\\"\`); | ||
}); | ||
" | ||
`; | ||
|
||
exports[`updates existing snapshot: updated snapshot 1`] = ` | ||
"test('updates existing snapshot', () => { | ||
expect(() => { | ||
throw new Error('apple'); | ||
}).toThrowErrorMatchingInlineSnapshot(\`\\"apple\\"\`); | ||
}); | ||
" | ||
`; | ||
|
||
exports[`works fine when function throws error: initial write 1`] = ` | ||
"test('works fine when function throws error', () => { | ||
expect(() => { | ||
throw new Error('apple'); | ||
}).toThrowErrorMatchingInlineSnapshot(\`\\"apple\\"\`); | ||
}); | ||
" | ||
`; |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
prettierPath
? Not sure