Enable snapshot property matcher functionality for addon-storyshots
See original GitHub issueIf you are creating a issue to track work to be completed, start here:
Work summary
With jest 23, snapshot property matchers were introduced as a way to exempt props from causing red snapshots. It is summarized best by this tweet: https://twitter.com/fbjest/status/999733224178896896?lang=en
There is currently no way to make use of this functionality while using the snapshot testing functions exported by addon-storyshots.
Where to start
I would like to add an additional parameter to snapshotWithOptions
and multiSnapshotWithOptions
that gets passed through as an argument to toMatchSnapshot
and toMatchSpecificSnapshot
respectively. This argument can then be used to pass the required property matchers to jest
example usage:
import initStoryshots, {
multiSnapshotWithOptions,
} from '@storybook/addon-storyshots';
initStoryshots({
framework: 'react',
storyKindRegex: /^((?!.*?ErrorBoundary).)*$/,
test: multiSnapshotWithOptions({
propertyMatchers: { timestamp: expect.any(Number) },
}),
});
Acceptance criteria
- [ ] Snapshot property matchers can be passed via
snapshotWithOptions
andmultiSnapshotWithOptions
- Passed property matchers are respected by the storyshots test
Who to contact
Issue Analytics
- State:
- Created 5 years ago
- Reactions:9
- Comments:12 (5 by maintainers)
Top Results From Across the Web
Storyshots Addon | Storybook: Frontend workshop for UI ...
Configure Storyshots for HTML snapshots. Create a new test file with the name Storyshots.test.js . (Or whatever the name you prefer, as long...
Read more >StoryShots Adds Automatic Jest Snapshot Testing for Storybook
Configure Storyshots for HTML snapshots ... Create a new test file with the name Storyshots.test.js . (Or whatever the name you prefer, as...
Read more >@storybook/addon-storyshots | Yarn - Package Manager
Fast, reliable, and secure dependency management.
Read more >Storybook Snapshot Testing - In Plain English
Automatic Jest Snapshot Testing with Storybook Stories. ... create a test file that can be picked up by Jest and run the Storyshots...
Read more >Angular Archives - Digital Innovation Blog - ZEISS Group
import { imageSnapshot } from '@storybook/addon-storyshots-puppeteer';. import path from 'path';. // Function to customize the snapshot location.
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 Free
Top 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
Any chance for this support. We use several libraries that set Ids and other things that change when rebuilding - we do not want those snapshots to fail for those changes.
hey @shuklajay117,
really great that you want to tackle this problem!
the biggest problem will probably be getting the property matchers to apply to the “objects” (i.e. react components) coming in. i would start by getting them to work in a local enviroment with
react-test-renderer
to get an understanding of how they work when combined with components.when you have a solid handle on that, try matching to objects returned from the enzyme renderer. you probably have to serialize them first (storybook uses the
enzyme-to-json
serializer by default, so i would try with that one). this is where i suspect the “monkey” of this feature by the way. enzyme objects are way more complex and not as easy to match.when you have that working, port that solution into the appropriate files of the addon. again, start with the simple one (
snapshotWithOptions
) and when you get that working,multiSnapshotWithOptions
. For the second one, there might be a PR ontojest-specific-snapshot
required.