RealOrangeOne / react-native-mock

A fully mocked and test-friendly version of react native (maintainers wanted)
MIT License
571 stars 153 forks source link

ReferenceError: FormData is not defined #103

Closed GeoffreyPlitt closed 7 years ago

GeoffreyPlitt commented 7 years ago

Hello,

The (real) React-Native has a global "FormData" defined. This module doesn't seem to provide that?

RealOrangeOne commented 7 years ago

I did not know about this global, and I don't believe it's documented. Do you know what it does? So we can make an accurate mock

ZauberNerd commented 7 years ago

Seems like it's inspired by the browser FormData API: https://developer.mozilla.org/en-US/docs/Web/API/FormData Here's the react-native implementation: https://github.com/facebook/react-native/blob/9ee815f6b52e0c2417c04e5a05e1e31df26daed2/Libraries/Network/FormData.js

RealOrangeOne commented 7 years ago

Ah ok. Looks like it's something that's very easy to add

GeoffreyPlitt commented 7 years ago

Sweet

cubbuk commented 7 years ago

I have a several issue with RNGoogleSignin component. I extended the current package in an initial config file similar to following, is there anything wrong with this approach I was getting an error while trying to run tests due to missign RNGoogleSignin:

import ReactNativeMock from "react-native-mock";
import "react-native-mock/mock";
ReactNativeMock.NativeModules.RNGoogleSignin = {};
RealOrangeOne commented 7 years ago

@cubbuk You probably shouldnt do it like that. If you just run the mock script. then extend NativeModules off react-naive instead of react-native-mock, it should work

cubbuk commented 7 years ago

@RealOrangeOne But isn't the idea of ReactNativeMock is to replace import statements to ReactNative to point to itself? If I extend ReactNative rather than the mock, the require statements on missing components will throw exception. Maybe I am just confused about the library let me know If I didn't make sense.

RealOrangeOne commented 7 years ago

I think you may be. We're changing the require path yes. But you shouldnt be mutating our library directly. You should be running mock, the changing react-native itself afterwards.

taylesworth commented 7 years ago

Is there any reason this isn't as simple as just adding the React Native implementation to react-native-mock? If that's all that's required, I'm happy to put together a PR.

RealOrangeOne commented 7 years ago

@taylesworth Yes, it should be just that simple. Provided it's mocked in an identical way.

taylesworth commented 7 years ago

Do you have an eta for a release containing FormData?