Open lingomksr opened 1 week ago
Hi @lingomksr the new API for graphql clients in V6 is from generateClient
to initialize a client. You should be able to mock client.graphql
instead of API.graphql
https://docs.amplify.aws/react/build-a-backend/data/connect-to-API/#generate-the-amplify-data-client
Let me know if that helps!
HI @chrisbonifacio,
I tried to use like this
const amplifyClient = generateClient();
const apiSpy = jest.spyOn(amplifyClient, "graphql").mockImplementation(() => {
return of(mockResponse);
});
But its not throws type mismatch build error!
Hi @lingomksr , I would recommend checking out how we test subscriptions in our library:
https://github.com/aws-amplify/amplify-js/tree/main/packages/api-graphql/__tests__
If that doesn't help, I'll try and see if I can get you some feedback and/or guidance on your tests.
Also, can you please share the error message you're seeing?
Before opening, please confirm:
JavaScript Framework
React
Amplify APIs
GraphQL API
Amplify Version
v6
Amplify Categories
No response
Backend
Other
Environment information
Describe the bug
I am just upgraded the aws-amplify from v5 to v6. Seems subscriptions working fine. I tried to create mock response for those subscriptions. In v5 I used spyon to create mock response.
jest.spyOn(API, "graphql").mockImplementation(() => { return of(mockResponse); });
But in V6 seems API is removed. I am not able to mock those subscription.
Expected behavior
Mock should work with v6
Reproduction steps
create spyon for subscription
Code Snippet
Log output
aws-exports.js
No response
Manual configuration
No response
Additional configuration
No response
Mobile Device
No response
Mobile Operating System
No response
Mobile Browser
No response
Mobile Browser Version
No response
Additional information and screenshots
No response