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.

Enable snapshot property matcher functionality for addon-storyshots

See original GitHub issue

If 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 toMatchSpecificSnapshotrespectively. 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 and multiSnapshotWithOptions
  • Passed property matchers are respected by the storyshots test

Who to contact

@tobilen

Issue Analytics

  • State:open
  • Created 5 years ago
  • Reactions:9
  • Comments:12 (5 by maintainers)

github_iconTop GitHub Comments

3reactions
waynebrantleycommented, Aug 7, 2019

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.

2reactions
tobilencommented, Jul 23, 2018

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 onto jest-specific-snapshot required.

Read more comments on GitHub >

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

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