linearlabs-workspace / storybook-addon-mock

This addon allows you to mock fetch or XMLHttpRequest in the storybook.
https://storybook-addon-mock.netlify.app
MIT License
112 stars 46 forks source link

Problem with mocking N requests of one type [GET]. #204

Open MaciejDybowski opened 10 months ago

MaciejDybowski commented 10 months ago

I have a problem with mock requests of the same type. Namely, the data is mocked only for the last request from the mockData array.

image

image

In the #64 issue reportedly solved the problem. Am I doing something wrong?

Versions storybook-addon-mock -4.3.0 Storybook 7.6.5

@nutboltu

dd commented 8 months ago

It seems that the issue lies specifically with handling GET parameters. Different links with GET requests are processed successfully, but multiple instances with the same link but different GET parameters are not. However, your problem with the appearance of a fix can be solved by either moving the GET parameters into the URL - /api/currencies/<page>, or by creating a single object with a function in response, and forming the necessary response based on the GET parameters there:

export constStandart = {
    mockAddonConfigs: {
        globalMockData: [
        {
                url: '/api/currencies',
                method: 'GET',
                status: 200,
                response: ({ searchParams: { page, size }}) => {
                    ...
                },
            },
        ],
        ignoreQueryParams: true,
        disableUsingOriginal: true,
    },
};