question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[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:open
  • Created 5 years ago
  • Reactions:5
  • Comments:17 (9 by maintainers)

github_iconTop GitHub Comments

3reactions
Andaristcommented, Jun 3, 2018

I don’t get why this new matcher would improve on the current approach

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.

Is the exports causing issues?

Taking babel as an example. Keeping expected.js without exports 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.

1reaction
SimenBcommented, Feb 26, 2022

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?

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found