google-signin: Jest test case fails
I’m unable to figure out how to do I fix this jest error when using google sign in
Test suite failed to run
TypeError: Cannot read property 'BUTTON_SIZE_ICON' of undefined
at Object.<anonymous> (node_modules/react-native-google-signin/GoogleSignin.ios.js:34:20)
at Object.<anonymous> (node_modules/react-native-google-signin/index.js:1:107)
at Object.<anonymous> (app/components/screens/login/login.js:6:30)
can you look at it and tell me if there is something I can fix to resolve this issue.
About this issue
- Original URL
- State: closed
- Created 8 years ago
- Reactions: 10
- Comments: 18
works for me! You can run this code before each test using setupTestFrameworkScriptFile
For people still coming here from google searches, I just integrated this with the current version of ‘@react-native-community/google-signin’ and this mock (in
__mocks__/@react-native-community/google-signin.tsso it was picked up automatically - no entry in jest.config.js) seemed to work for me:After some trial and error, I managed to make it work by adding an empty file named
react-native-google-signin.jsin my__mock__folder. Not that I fully understand why this works…I cant seem to find a solution for this error. mocking does not work anymore… I still get an error while running test.
` TypeError: Cannot read property ‘SIGN_IN_CANCELLED’ of undefined
How about mock like this?
@sammysium @haveamission 👋 did you manage to find a workaround? 😄 I found that if I wrap the dependencies in my own file e.g.
config/google_signin.tsthen I can mock that more easily:along with
test/__mocks__/react-native_modules.ts:which is loaded from
package.json:Now in my components, I just load the components from
config/google_signininstead, which is the file that callsconfigure()in the first place.@mikehardy had to import
__mocks__/@react-native-community/google-signin.tsin myjest.setup.jswhich is one of the setup files mentioned injest.config.js. But it’s working now, thanks.Having same problem still any fix ?
Should this be closed if it isn’t actually fixed? Adding ‘react-native-google-signin.js’ into my mock folder was working but it has suddenly breaking again.