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

MockedProvider throws an error in a subsequent test when a mock is missing #6378

Closed
BenoitHiller opened this issue Jun 3, 2020 · 1 comment

Comments

@BenoitHiller
Copy link

I attempted to perform the following two tests of a component in order using MockedProvider:

  1. Test that the component shows a loading state when a the query is still loading by passing in mocks={[]}
  2. Test that the component shows a result when the same query is done loading

Intended outcome:
Either both tests pass or only the first test passes.

Actual outcome:
The second test fails unless the tests are performed in the opposite order

How to reproduce the issue:

  1. Use the MockedProvider with an empty mocks list.
  2. Allow the event loop to move forward such as with a setTimeout promise.
it('succeeds', () => {
  const component = renderer.create(
    <MockedProvider mocks={[]}>
      <App />
    </MockedProvider>
  );
});

it('fails', async () => {
  await new Promise((resolve) => setTimeout(resolve, 0));
});

You can see a longer reproduction closer to the actual code as well as a runnable version of the above in this fork of the error reproduction repository.

Versions

  System:
    OS: macOS 10.15.4
  Binaries:
    Node: 12.13.1 - ~/.nvm/versions/node/v12.13.1/bin/node
    Yarn: 1.21.1 - ~/.nvm/versions/node/v12.13.1/bin/yarn
    npm: 6.12.1 - ~/.nvm/versions/node/v12.13.1/bin/npm
  Browsers:
    Chrome: 83.0.4103.61
    Firefox: 72.0.2
    Safari: 13.1
  npmPackages:
    @apollo/client: ^3.0.0-rc.0 => 3.0.0-rc.0
benjamn added a commit that referenced this issue Oct 1, 2020
See benjamn/wryware#21 for explanation and
motivation. Should help with #6771, #6803, #6688, #6378, and #7081, and
possibly other regressions that began in @apollo/[email protected].
benjamn added a commit that referenced this issue Oct 1, 2020
See benjamn/wryware#21 for explanation and
motivation. Should help with #6771, #6803, #6688, #6378, and #7081, and
possibly other regressions that began in @apollo/[email protected].
@hwillson
Copy link
Member

hwillson commented May 3, 2021

#7108 should have fixed this - let us know if not - thanks!

@hwillson hwillson closed this as completed May 3, 2021
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Feb 15, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants