I have 2 mutate gql query that I need to mock them in my unit test. For unit tests I am using react test library. during my function test 2 different mutate is being called and I have to find a way to differentiate between them, so inside my test it will know which one is being called in the correct order.
here are 2 mutate gql:
export const closeMultipartUpload: any = gql`
mutation closeMultipartUpload(
$directoryID: String!
$uploadID: String!
) {
closeMultipartUpload(
directoryID: $directoryID
uploadID: $uploadID
) {
versionID
}
}
`;
export const fileUploadMutation = gql`
mutation createUploadUrl(
$directoryID: String!
) {
createUploadUrl(
directoryID: $directoryID
requesterID: $requesterID
) {
url
documentID
}
}
`;
to mock this APIs I have below in my test:
graphql.mutate = jest.fn().mockImplementation(() =>
Promise.resolve({
data: {
'createUploadUrl': {
'url': 'foo',
'documentID': '123
}
},
})
);
but I cannot mock the same way for the other API call, since react test library can recognize which one is which. i thought spy on
can help. but it did not or at least I am not using it correctly.
I will appreciate your help
1条答案
按热度按时间mnemlml81#
Probably a good idea to have an Apollo Provider, and provide the state of the request and response as demo'd here in the docs https://www.apollographql.com/docs/react/development-testing/testing/