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

When updating the list of mocks and calling 'rerender' on the component under test, the updated list of mocks is ignored and the original is still used. #11982

Closed
jfstephe opened this issue Aug 1, 2024 · 4 comments
Labels

Comments

@jfstephe
Copy link

jfstephe commented Aug 1, 2024

Issue Description

On my project we are migrating use MockedProvider and in our tests we build up the mocks, step by step, starting with an initial set of mocks and then adding to it as the test scenario builds up. We don't want to setup/define all the mocks up-font.

When trying this out we are seeing that the updated list of mocks isn't used in a render and the original mocked list is still being used.

A codesandbox, based off the one in the documentation, is attached demonstrating this - see the 'should render another newly added Dog' test.

Link to Reproduction

https://codesandbox.io/p/sandbox/condescending-jang-cstl3k?file=%2Fsrc%2Fdog.test.js%3A36%2C40

Reproduction Steps

See codesandbox.

@apollo/client version

3.11.2

@phryneas
Copy link
Member

phryneas commented Aug 1, 2024

MockedProvider will use MockLink internally. MockLink copies the mocks array on initialization and then keeps working on that.
It doesn't watch for modifications of the original array (and even if it did, relying on something like that would be relying on an implementation detail).

That said, MockLink has a addMockedResponse method to dynamically add new mocks - maybe that would work for you?

@jfstephe
Copy link
Author

jfstephe commented Aug 1, 2024

Awesome, thanks for the quick response. I used the MockLink and the tests are passing. 👍
(Although, I'm not sure I agree with implementation detail, I'd rather fall back on the principle of least surprise).

@jfstephe jfstephe closed this as completed Aug 1, 2024
Copy link
Contributor

github-actions bot commented Aug 1, 2024

Do you have any feedback for the maintainers? Please tell us by taking a one-minute survey. Your responses will help us understand Apollo Client usage and allow us to serve you better.

Copy link
Contributor

github-actions bot commented Sep 1, 2024

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.
For general questions, we recommend using StackOverflow or our discord server.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Sep 1, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

3 participants