Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mocking in storyshots #962

Closed
tehandyb opened this issue Apr 26, 2017 · 4 comments
Closed

Mocking in storyshots #962

tehandyb opened this issue Apr 26, 2017 · 4 comments

Comments

@tehandyb
Copy link

tehandyb commented Apr 26, 2017

Is it possible to Mock components when using storyshots? I can't see any documentation to do it.

@evenchange4
Copy link
Contributor

Yes, it is possible. I mock several components for storyshots with Jest config:

"setupFiles": [
  "<rootDir>/.storybook/storyshots-setup.js"
],
// .storybook/storyshots-setup.js"
jest.mock('react-motion-ui-pack');
...

Reference: https://github.com/MCS-Lite/mcs-lite/blob/master/packages/mcs-lite-ui/package.json#L30

@tehandyb
Copy link
Author

Awesome, thanks!

@horacio10x
Copy link

If you want to mock for the storyshots only you can put your mock above initStoryshots()

jest.mock('../someMock', () =>
  () => `mock`
);
initStoryshots();

@dheerajk02
Copy link

If you want to mock for the storyshots only you can put your mock above initStoryshots()

jest.mock('../someMock', () =>
  () => `mock`
);
initStoryshots();

@horacio10x @evenchange4 I get the following error if I try to jest mock right before the initStoryshots();
Do not import @jest/globals outside of the Jest test environment

// @ts-nocheck
import initStoryshots, { multiSnapshotWithOptions } from "@storybook/addon-storyshots";
import ReactDOM from "react-dom";
import path from "path";
jest.mock("@storybook/core/server", () => ({
    toRequireContext: require("@storybook/core/dist/server/preview/to-require-context").toRequireContext,
}));
ReactDOM.createPortal = node => node;
initStoryshots({
    configPath: path.resolve(__dirname, "../../.storybook"),
    test: multiSnapshotWithOptions({}),
});

@akanksha-swiggy

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants