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 multiple mocks in the same story. #64

Closed
NicolasBonduel opened this issue Nov 11, 2021 · 3 comments · Fixed by #66
Closed

Problem with multiple mocks in the same story. #64

NicolasBonduel opened this issue Nov 11, 2021 · 3 comments · Fixed by #66

Comments

@NicolasBonduel
Copy link
Contributor

NicolasBonduel commented Nov 11, 2021

I am trying to mock multiple requests for the same component, such as:

Appointment.parameters = {
  mockData: [
    {
        url: `${process.env.ENDPOINT}/appointments/CURRENT`,
        response: responses.CURRENT,
    },
    {
        url: `${process.env.ENDPOINT}/appointments/EARLY`,
        response: responses.EARLY,
    },
    {
        url: `${process.env.ENDPOINT}/appointments/LATE`,
        response: responses.LATE,
    },
    {
        url: `${process.env.ENDPOINT}/appointments/CANCELLED`,
        response: responses.CANCELLED,
    },
  ],
};

It seems that only the latest mockData of the array is used, and the other ones are ignored. Am I doing something wrong?

@adamgilmour
Copy link

Yep, I'm experiencing the same issue

@NicolasBonduel
Copy link
Contributor Author

I found the issue and fixed it in the PR above.

An easy way to fix it in the meantime is to set the method in each mockData. On my example, it would be:

Appointment.parameters = {
  mockData: [
    {
        url: `${process.env.ENDPOINT}/appointments/CURRENT`,
        response: responses.CURRENT,
        method: 'GET',
    },
    {
        url: `${process.env.ENDPOINT}/appointments/EARLY`,
        response: responses.EARLY,
        method: 'GET',
    },
    {
        url: `${process.env.ENDPOINT}/appointments/LATE`,
        response: responses.LATE,
        method: 'GET',
    },
    {
        url: `${process.env.ENDPOINT}/appointments/CANCELLED`,
        response: responses.CANCELLED,
        method: 'GET',
    },
  ],
};

@adamgilmour, this might be interesting for you.

@nutboltu
Copy link
Collaborator

@NicolasBonduel the change reflects on version 1.7.0

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

Successfully merging a pull request may close this issue.

3 participants