storybook-addon-mock
storybook-addon-mock copied to clipboard
Problem with mocking N requests of one type [GET].
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.
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
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,
},
};