[proposal] Fixture/snapshot tests - write in separate files
See original GitHub issue🚀 Feature Proposal
Allow each fixture/snapshot test to be written to separate file WITHOUT wrapping snapshot output into exports
property.
Motivation
It would be highly useful for projects like babel to treat their current fixture tests (actual.js / expected.js pairs) as Jest snapshots. This would allow integrating with jest more easily and using snapshot features for those tests (like -u
)
Example
API would have to be decided, this is just a one proposal:
expect('test/fixtures/**/actual.js', ({ filename, code }) =>
babel.transform(code, {
filename
}).code
).toMatchFixtureSnapshot('expected.js')
Pitch
This with inline snapshot features would make a nice, complete package and cover most use cases.
Issue Analytics
- State:
- Created 5 years ago
- Reactions:5
- Comments:17 (9 by maintainers)
Top Results From Across the Web
Snapshot Testing
A typical snapshot test case renders a UI component, takes a snapshot, then compares it to a reference snapshot file stored alongside the...
Read more >Snapshot Testing React Components with Jest
Learn how to test React components without writing a lot of code by using Jest and its new snapshot testing feature.
Read more >NEWS
testthat now uses brio for all reading and writing (#1120). ... If a test containing multiple snapshots fails (or skips) in between snapshots, ......
Read more >What's wrong with snapshot tests. ...
When you write expect(mycomponent).toMatchSnapshot() , Jest creates a snapshot file, like mytest.spec.js.snap , with all snapshots of your test file. You ...
Read more >zoroaster
The 2020 Most Modern Testing Framework For Node.JS With Test Contexts (Reusable BeforeEach / AfterEach Via Separate Files); Masks (Inputs/Outputs In Non-Js ...
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
The problem with current approach is that snapshots are colocated to the file that is doing an
expect
call. With fixtures such as in babel desired scenario is to keep expected snapshots colocated with input fixtures.Taking
babel
as an example. Keepingexpected.js
withoutexports
wrapper is way nicer, because the output is actual code and when inspecting such an output file you get i.e. syntax highlighting for free.We should stick links to https://github.com/americanexpress/jest-image-snapshot and https://github.com/satya164/jest-file-snapshot in https://jestjs.io/docs/snapshot-testing.
PR is still welcome to make
_updateSnapshot
public - probably under a more descriptive name?