Mocking API.graphql(...).subscribe(...) using Jest
See original GitHub issueWhich Category is your question related to? API, in particular graphql
What AWS Services are you utilizing? AppSync
Provide additional details e.g. code snippets I need to have 100% coverage in my app (its a react app that uses amplify-cli, which in turn uses amplify-js, and I need some guidance into mocking the API subscriptions. This is a piece of code I need to mock in order to test (I am using jest, obviously anything else would work if there are other tools you guys know):
API.graphql(
graphqlOperation(subscriptions.onCreateItem, { owner: username })
).subscribe({
next: (item) => {
// Do something with the code, irrelevant for the purposes of this question.
}
})
I’ve looked at https://www.apollographql.com/docs/graphql-tools/mocking.html, plus google searched, looked into this repo at the tests that you guys have and also into amplify-cli, but I can’t seem to get it working. If you have any code examples that would be great, I don’t need hand holding to mock the above, just a good example or two that I can take inspiration from.
You guys have a test from subscriptions, but its being skipped (it’s https://github.com/aws-amplify/amplify-js/blob/master/packages/api/__tests__/API-test.ts#L268 and I couldn’t get it working either - I’m getting a GraphQL Network error)
Issue Analytics
- State:
- Created 5 years ago
- Comments:7 (1 by maintainers)
Top GitHub Comments
Any movement on this? I just spent yesterday beating my head against this. I opened up another defect WRT testing and Amplify. I kind of have a love/hate relationship with the stack at this point.
This issue has been automatically locked since there hasn’t been any recent activity after it was closed. Please open a new issue for related bugs.
Looking for a help forum? We recommend joining the Amplify Community Discord server
*-help
channels or Discussions for those types of questions.