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 mockResponseOnce #9

Open
gsasouza opened this issue Nov 20, 2018 · 1 comment
Open

Add mockResponseOnce #9

gsasouza opened this issue Nov 20, 2018 · 1 comment

Comments

@gsasouza
Copy link

gsasouza commented Nov 20, 2018

Add a function that allow to change mock return in each test.

Use case:

  • I have a query for user login and i need to test success and some fail tests, then in each test the returned value will be different.

Proposal:

  • I'm thinking in something like this package function mockResponseOnce.
@robrichard
Copy link
Member

I think you can do this without changes to this library. You can write a function for your network layer that returns different invocations of getNetworkLayer

Network.create((operation, variables) => {
  if (variables.email === "failure-test@example.com") {
    // mock failed login test case
    return getNetworkLayer({
      schema,
      mocks: {
        User: () => {
          throw new Error("login failed");
        }
      }
    })(operation, variables);
  }
  // mock successful login test case
  return getNetworkLayer({
    schema,
    mocks: {
      User: () => ({
        id: "123"
      })
    }
  })(operation, variables);
});

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