Skip to content

Commit 0864ff8

Browse files
authored
Update Dynamic variables testing guide (#12978)
`variableMatcher` was removed from `Mocklink.MockedResponse` on Apollo Client 4
1 parent cc1e467 commit 0864ff8

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

docs/source/development-testing/testing.mdx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,7 @@ Passing `Number.POSITIVE_INFINITY` will cause the mock to be reused indefinitely
184184

185185
### Dynamic variables
186186

187-
Sometimes, the exact value of the variables being passed are not known. The `MockedResponse` object takes a `variableMatcher` property that is a function that takes the variables and returns a boolean indication if this mock should match the invocation for the provided query. You cannot specify this parameter and `request.variables` at the same time.
187+
Sometimes, you don't know the exact value of the variables for a query. The `variables` property of the `MockedResponse` object accepts a callback function that takes the variables and returns a boolean indicating whether this mock should match the invocation for the provided query.
188188

189189
For example, this mock will match all dog queries:
190190

@@ -194,8 +194,8 @@ import { MockedResponse } from "@apollo/client/testing";
194194
const dogMock: MockedResponse<Data, Variables> = {
195195
request: {
196196
query: GET_DOG_QUERY,
197+
variables: (variables) => true,
197198
},
198-
variableMatcher: (variables) => true,
199199
result: {
200200
data: { dog: { __typename: "Dog", id: 1, name: "Buck", breed: "poodle" } },
201201
},
@@ -210,14 +210,14 @@ import { MockedResponse } from "@apollo/client/testing";
210210
const dogMock: MockedResponse<Data, Variables> = {
211211
request: {
212212
query: GET_DOG_QUERY,
213+
variables: jest.fn().mockReturnValue(true),
213214
},
214-
variableMatcher: jest.fn().mockReturnValue(true),
215215
result: {
216216
data: { dog: { __typename: "Dog", id: 1, name: "Buck", breed: "poodle" } },
217217
},
218218
};
219219

220-
expect(variableMatcher).toHaveBeenCalledWith(
220+
expect(dogMock.request.variables).toHaveBeenCalledWith(
221221
expect.objectContaining({
222222
name: "Buck",
223223
})

0 commit comments

Comments
 (0)