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

Global mock decorator #110

Closed
marcusmolchany opened this issue May 27, 2022 · 1 comment
Closed

Global mock decorator #110

marcusmolchany opened this issue May 27, 2022 · 1 comment
Labels
feature request New feature or request

Comments

@marcusmolchany
Copy link

marcusmolchany commented May 27, 2022

Is there a way to write a single storybook-addon-mock decorator (maybe in .storybook/preview.js) that applies to all of my stories?

I tried this in .storybook/preview.js and it did not work for me:

import withMock from "storybook-addon-mock";

const ApiRequestMock = ({ children }) => {
  return <>{children}</>;
};
const BoundApiRequestMock= ApiRequestMock.bind({});
BoundApiRequestMock.parameters = {
  mockData: [
    {
      url: "/api/my_endpoint",
      method: "GET",
      status: 200,
      response: {
        data: "my data"
      }
    }
  ]
};

export const decorators = [
  withMock,
  (Story, context) => (
    <BoundApiRequestMock>
      <Story context={context} />
    </BoundApiRequestMock>
  )
];
@nutboltu nutboltu added the feature request New feature or request label Jun 2, 2022
@nutboltu
Copy link
Collaborator

This feature is implemented in 3.0.0.
https://storybook-addon-mock.vercel.app/?path=/story/docs-advanced-setup--page

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

No branches or pull requests

2 participants