You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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
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.
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?
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).
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.
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.
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
version3.11.2
The text was updated successfully, but these errors were encountered: