Closed jfstephe closed 2 months ago
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