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

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

Open
MaciejDybowski opened this issue Dec 20, 2023 · 1 comment
Open

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

MaciejDybowski opened this issue Dec 20, 2023 · 1 comment

Comments

@MaciejDybowski
Copy link

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
Copy link

dd commented Mar 5, 2024

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

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

2 participants