Comments (6)
In case someone runs into this, that's how I did it for integrating jest-styled-components into storyshots:
import registerRequireContextHook from 'babel-plugin-require-context-hook/register';
import initStoryshots, {
Stories2SnapsConverter,
} from '@storybook/addon-storyshots';
import renderer from 'react-test-renderer';
import 'jest-styled-components';
import { styleSheetSerializer } from 'jest-styled-components/serializer';
import { addSerializer } from 'jest-specific-snapshot';
addSerializer(styleSheetSerializer);
registerRequireContextHook();
initStoryshots({
test: ({ story, context }) => {
const converter = new Stories2SnapsConverter();
const snapshotFilename = converter.getSnapshotFileName(context);
const storyElement = story.render(context);
const tree = renderer.create(storyElement).toJSON();
expect(tree).toMatchSpecificSnapshot(snapshotFilename);
}
});
from jest-styled-components.
I'm not a storybook
expert but it seems right, and it works as expected.
Nit: You could avoid passing the second param to the create
method:
const tree = renderer.create(storyElement).toJSON()
I'm about to rewrite the docs with v4, do you mind if I reference your repo as an example of how to use this package with storybook
?
from jest-styled-components.
Of course I don't mind! :)
P.S. I'll do the nit fix
from jest-styled-components.
Perfect, thanks @wongterrencew!
from jest-styled-components.
@rwieruch that code almost worked for me, thanks. The one change required was to work around a "ReferenceError: renderer is undefined":
replace this:
import renderer from 'react-test-renderer';
with this:
import * as renderer from 'react-test-renderer';
See also: facebook/react#11158 (comment)
from jest-styled-components.
I'm not a
storybook
expert but it seems right, and it works as expected.Nit: You could avoid passing the second param to the
create
method:
const tree = renderer.create(storyElement).toJSON()
I'm about to rewrite the docs with v4, do you mind if I reference your repo as an example of how to use this package with
storybook
?
I don't see this mentioned in the docs. Has it been removed since then?
from jest-styled-components.
Related Issues (20)
- jest-styled-components uses global.beforeEach rather than global.beforeAll or both? HOT 2
- getHTML() is failing, not sure why. HOT 1
- toHaveStyleRule is not compatible with some displayNames if fileName is used
- Child component className value regression from 7.0.7 to 7.0.8 HOT 2
- `setStyleSheetSerializerOptions` types not working HOT 1
- Create wrapper matcher around .toHaveStyleRule
- Doesn't seem to support Jest 28.x.x HOT 6
- [Bug] wrong className generated
- tabs vs spaces
- [Bug] Chained selectors with pseudo-state filters are parsed incorrectly in v7.1.1 HOT 1
- More diffs showing on unchanged snapshot lines
- Dft
- Not working correctly with @testing-library/react HOT 3
- Library is not applied to tests where the Renderer object was created in a 'describe'
- Doesn't seem to support Jest 28 and newest HOT 8
- toHaveStyleRule with @media rule breaks after styled-components update HOT 6
- TypeError: global.beforeEach is not a function HOT 6
- update adobe/css-tools to v4.3.2 due CVE-2023-48631
- Compatibility Issue with `jest-styled-components` and Storybook's `test-runner`
- TypeError: document.querySelectorAll is not a function
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from jest-styled-components.