jefflau / jest-fetch-mock

Jest mock for fetch
MIT License
886 stars 118 forks source link

FormData is not defined #23

Open jhalborg opened 7 years ago

jhalborg commented 7 years ago

Can't use the lib for testing FormData bodies it seems - getting FormData is not defined.

jhalborg commented 7 years ago

Maybe inspiration can be found here https://github.com/RealOrangeOne/react-native-mock/blob/master/src/Libraries/Network/FormData.js

MrHubble commented 6 years ago

@jhalborg do you mind sharing how you ended up testing FormData ?

jhalborg commented 6 years ago

I never did, ended up skipping those tests, deadlines being deadlines. I posted a question on SO as well that received an answer recently, but haven't had time to test - maybe you are Marklar on SO? :-)

https://stackoverflow.com/q/45842088/1409779

MrHubble commented 6 years ago

Thanks for taking the time to reply. Yep, that's me on SO. I'll continue the discussion on SO with the person who provided an answer.

jefflau commented 6 years ago

@MrHubble Did you ever figure out what was going wrong?

MrHubble commented 6 years ago

@jefflau in the Stackoverflow question mentioned above I commented:

Adding global.FormData = ... before importing any other library did not work for me. What did end up working was:

jest.mock('react-native-aws3', () => { return { Request: { FormData: {} } } });. 

I'm not sure if this is the right thing to do as it appears I'll have to do it for a number of my dependencies