Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Example using GraphQL and React Native for Testing #1077

Open
Freire71 opened this issue Jan 11, 2023 · 2 comments
Open

Example using GraphQL and React Native for Testing #1077

Freire71 opened this issue Jan 11, 2023 · 2 comments

Comments

@Freire71
Copy link

Hi, I'm trying to integrate MirageJS in a existing React Native app that uses Apollo Client as it GraphQL client.
Using MirageJS for development works great, however inside test files I'm having some troubles to make it work.
Could you please provide an example for a React Native app that uses the GraphQL package?

@Freire71
Copy link
Author

Still having the same issue, It would be great to have an example talking about how to make it work for testing :)

@Freire71 Freire71 changed the title Example using GraphQL and React Native Example using GraphQL and React Native for Testing Jan 30, 2023
@Freire71
Copy link
Author

Freire71 commented Feb 2, 2023

Hi, I've found why my code was not working for testing, I've needed to add global.FormData = class FormData {} on jest.setup.js. This line of Pretender throws because FormData in undefined
whatwg-fetch is used because Apollo client is using the React Native implementation of fetch API but it does not exists for Node env.
This my final version of the jest.setup.js file

import 'whatwg-fetch';
global.self = global;
global.XMLHttpRequest = require('xmlhttprequest').XMLHttpRequest;
global.FormData = class FormData {};

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant