storybook-addon-mock icon indicating copy to clipboard operation
storybook-addon-mock copied to clipboard

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

Open MaciejDybowski opened this issue 1 year ago • 1 comments

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

MaciejDybowski avatar Dec 20 '23 11:12 MaciejDybowski

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,
    },
};

dd avatar Mar 05 '24 14:03 dd