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

mockData per story works only on page refresh after upgrade to v3 #142

Open
romanivna opened this issue Oct 20, 2022 · 0 comments
Open

mockData per story works only on page refresh after upgrade to v3 #142

romanivna opened this issue Oct 20, 2022 · 0 comments

Comments

@romanivna
Copy link

After upgrade to 3.2 mockData working only once when you refresh the page on certain story.
When switching between stories - it doesn't work anymore and I got 404 on request.
Meanwhile, the global overrides supposed to be working for all stories, but they also works only for the first one

So there's the code of component.stories.ts.

const TemplateWithNgContent: Story<Component> = (
  args: Component,
) => {
  return {
    props: {
      ...args,
    },
  };
};

export const defaultItemTemplate: Story<Component> = TemplateWithNgContent.bind(
  {},
);
defaultItemTemplate.parameters = {
  mockData: [
    {
      url: '/ppl/v1/clients',
      method: 'GET',
      status: 200,
      response: clientsResponse,
    },
  ],
};

export const templateWhenErrorHappens: Story<Component> =
  TemplateWithNgContent.bind({});
templateWhenErrorHappens.parameters = {
  mockData: [
    {
      url: '/ppl/v1/clients',
      method: 'GET',
      status: 500,
    },
  ],
};

So when I arrive on the page - no request, everything is fine
image

After switching to other story and back - mocks are lost
image

It happens not only when I put the mockData in the story itself. Same happens when it's written in the root stories level, like

export default {
  title: 'Component Title',
  component: Component,
  argTypes: {...},
  decorators: [...],
  parameters: {
    mockData: [{ url: '/v2/labels' .... }],
  },
}

I also have the translations call, so I've added it into preview.js of lib (we have nx monorepo)

export const parameters = {
  actions: { argTypesRegex: '^on[A-Z].*' },
  mockAddonConfigs: {
    globalMockData: [
      {
        url: '/v2/labels',
        method: 'GET',
        status: 200,
        response: labels,
      }
    ],
  },
};

Despite on mocked request (it mocked with query parameters also) - every time I change the story - request for labels fails.
First time when I refresh the page - no request goes and labels are returned from mocks.

image

In previous version there were no such issues at all - all was working perfectly.
Thanks in advance for your help.

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

No branches or pull requests

1 participant