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

Add a way to disable delay in runtime for all mocked requests #145

Open
isqua opened this issue Nov 3, 2022 · 4 comments
Open

Add a way to disable delay in runtime for all mocked requests #145

isqua opened this issue Nov 3, 2022 · 4 comments
Labels
feature request New feature or request

Comments

@isqua
Copy link

isqua commented Nov 3, 2022

Very useful plugin, thank you! I use it in many components to show loading and saving processes.

I also write screenshot tests on my Storybook components. I have to synchronize mock delay time and pause in my tests, which causes the tests to take a bit longer to run.

Usually, I would like to have no delays in my tests. So I would like to be able to turn off all delays in mocked request. For example, through global types or another way that can be controlled through the URL. Something like this:

// .storybook/preview.js

export const globalTypes = {
  mockDelay: {
    name: 'Mock delay',
    description: 'Enable/disable mock delays',
    defaultValue: 'enabled',
    toolbar: {
      icon: 'circlehollow',
      // Array of plain string values or MenuItem shape (see below)
      items: ['enabled', 'disabled'],
      // Property that specifies if the name of the item will be displayed
      showName: true,
      // Change title based on selected value
      dynamicTitle: true,
    },
  },
};

Do you think this is possible? What's the best way to implement it?

@nutboltu
Copy link
Collaborator

@isqua, you can set up the delay time from the addon panel. However, it won't fix your problem as we are using setTimeout even though the delay time is 0. I have to raise a PR to fix this issue. Any PR from your end will also welcome :)

@nutboltu nutboltu added the feature request New feature or request label Nov 24, 2022
@isqua
Copy link
Author

isqua commented Nov 24, 2022

@nutboltu, thank you for the response! Is it a way to change the value programmatically? setTimeout with 0 is not the issue for me, I just would to reduce the time needed for load data in tests.

@nutboltu
Copy link
Collaborator

There are no global types for that, as this is a special case. I would recommend using a separate mock data list for the load tests and using delay 0 in that mock data.

@isqua
Copy link
Author

isqua commented Nov 25, 2022

Yes, I am going to use something like this:

const meta: Meta<IMyComponentStoryArgs> = {
    title: 'components/MyComponent',
    decorators: [withMock],
    parameters: {
        mockData: adjustTimers([
            {
                url: '/api/mydata/success',
                method: 'PATCH',
                status: 201,
                delay: 500,
                response: {},
            },
            {
                url: '/api/mydata/error',
                method: 'PATCH',
                status: 502,
                delay: 500,
                response: {},
            },
        ]),
    },
};

export default meta;

and the adjustTimers will reset timers based on the environment. I just looking for a more native way :)

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

No branches or pull requests

2 participants