react-native-paper from 2.1.3 to 2.2.1 in a TypeScript projectts-jestTest suite failed to run
TypeError: Cannot read property 'reactNativeVersion' of undefined
2 | import { ScrollView, Text, TouchableOpacity, View } from 'react-native'
3 | import { Navigation } from 'react-native-navigation'
> 4 | import { Headline, Subheading } from 'react-native-paper'
| ^
5 |
6 | import { Button } from 'components/Button'
7 | import { SecureTextInput, TextInput } from 'components/TextInput'
at Object.<anonymous> (node_modules/react-native-paper/src/components/Switch.js:10:60)
at Object.<anonymous> (node_modules/react-native-paper/src/index.js:36:38)
at Object.<anonymous> (src/screens/Auth/SignUp/SignUp.tsx:4:1)
react-native-paper from 2.1.3 to 2.2.1ts-jest and see no type errorsNo errors are thrown when using version 2.1.3 or 2.2.0. I think this patch may be the cause? (I'm a bit newer to TypeScript)
https://github.com/callstack/react-native-paper/commit/0f52b7c3fb8f48fec861ffaec7faf9b8e133ff9a#diff-aa71c0e947fa44abf821ee560fe149e7R10
ts-jest is having trouble finding NativeModules.PlatformConstants type definition. The tsc compiler, on the other hand, is not throwing any errors.
| software | version
| --------------------- | -------
| ios or android | Mac OS Sierra
| react-native | 0.57
| react-native-paper | 2.2.1 or 2.2.2
| node | 11.0.0
| npm or yarn | 6.4.1
It's happening to me too after the changes made by @satya164. I am not using TS but the error is the same.
Don't know if mocking that could be a solution or it should work without mocking...
@stella-yc While there is no fix for this, you can mock Paper's Switch component and avoid this error. Something like this should do the job
jest.mock('react-native-paper/src/components/Switch', () => 'Switch');
You'll need to mock NativeModules for now. Maybe send a PR to React Native to add it? I'll add a check for now so you don't need a mock.
Thanks @satya164 for the quick reply and fix!
Thanks @satya164 for that quick fix! 馃挴
Most helpful comment
You'll need to mock
NativeModulesfor now. Maybe send a PR to React Native to add it? I'll add a check for now so you don't need a mock.