Giter Club home page Giter Club logo

Comments (6)

rwieruch avatar rwieruch commented on June 6, 2024 16

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.

MicheleBertoli avatar MicheleBertoli commented on June 6, 2024

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.

terrencewwong avatar terrencewwong commented on June 6, 2024

Of course I don't mind! :)

P.S. I'll do the nit fix

from jest-styled-components.

MicheleBertoli avatar MicheleBertoli commented on June 6, 2024

Perfect, thanks @wongterrencew!

from jest-styled-components.

techieshark avatar techieshark commented on June 6, 2024

@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.

papiro avatar papiro commented on June 6, 2024

@MicheleBertoli

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.