react-native-mock
react-native-mock copied to clipboard
TypeError: Cannot read property 'number' of undefined
I have an error with all my Views components
FAIL __tests__/components/Login.spec.js
● Test suite failed to run
TypeError: Cannot read property 'number' of undefined
at Object.<anonymous> (node_modules/react-native-mock/build/propTypes/LayoutPropTypes.js:21:37)
at Object.<anonymous> (node_modules/react-native-mock/build/propTypes/ViewStylePropTypes.js:6:22)
at Object.<anonymous> (node_modules/react-native-mock/build/components/View.js:6:25)
My deps:
"dependencies": {
"react": "^16.0.0-alpha.13",
"react-native": "^0.45.1",
"react-native-image-picker": "0.26.3",
"react-native-linear-gradient": "2.0.0",
"react-native-material-textfield": "0.6.0",
"react-native-mock": "^0.3.1",
"react-native-scrollable-tab-view": "0.6.6",
"react-native-snackbar": "0.3.6",
"react-native-vector-icons": "4.2.0",
"react-navigation": "1.0.0-beta.11",
"react-redux": "5.0.5",
"redux-saga": "0.15.3",
"styled-components": "^2.1.0"
},
"devDependencies": {
"babel-jest": "20.0.0",
"babel-preset-react-native": "1.9.2",
"chai": "4.0.2",
"chai-as-promised": "7.0.0",
"colors": "1.1.2",
"cors": "2.8.3",
"cucumber": "2.0.0-rc.9",
"debug": "2.6.8",
"express": "4.15.3",
"jest": "20.0.0",
"lodash": "4.17.4",
"react-test-renderer": "16.0.0-alpha.6",
"redux": "3.6.0",
"standard": "10.0.2",
"wd": "1.2.0"
},
That's a very strange error, possibly an issue to do with proptypes? Are your components using the number
proptype validator?
Also, possibly unrelated, you seem to be using both jest
, and a far newer version of react-native
than react-native-mock
supports. This may also be a factor in this issue.
Hi, i don´t use any proptypes validator in my components.
You are right, i think is relationated with this
Note: React.PropTypes is deprecated as of React v15.5. Please use the prop-types library instead.
What versions of jest and react-native supports react-native-mock?
Documentation on support is unfortunately kinda lacking.
I dont have support for any version of jest
, as it has a builtin mock of react-native
, however there's theoretically nothing stopping it working. The latest version of react-native
i've tested this on is 0.42
, however i'm planning to add better support for current a newer versions soon
Ok, thank you very much, I'll wait for the new version.
@ToniChaz you can test out #140 by installing the latest commit from github: npm install --save-dev github:RealOrangeOne/react-native-mock#master
According to me it is because the package still imports the propTypes from react.
It should use the package prop-types
to get the propTypes.
Any expectations when it will be fixed?
Has anyone figured out a way around this besides downgrading react/react-native?
Any updated here?
you need react < 16, one fix would be to fork it and set dependency of react < 16. If your project is on react >= 16 I think that's what you'd have to do.
@RealOrangeOne you should consider this
It should use the package prop-types to get the propTypes.
@RealOrangeOne Any fix for this issue ? Im using latest RN v51 & React 16.
I have a pull request that fixes this https://github.com/RealOrangeOne/react-native-mock/pull/158
Once you have the updated package, you'll need to go into node_modules/react-native-mock and run npm run build
before it will compile.
I have the same issue 😕
@gabrielrotbart i'm trying to install your version of react-native-mock
but ran into duplicated module error with the dependencies of the mock.
The name `setupDevtools` was looked up in the Haste module map. It cannot be resolved, because there exists several different files, or packages, that provide a module for that particular name and platform. The platform is generic (no extension). You must delete or blacklist files until there remains only one of these:
* `/<project_root>/node_modules/react-native-mock/node_modules/react-native/Libraries/Core/Devtools/setupDevtools.js` (module)
* `/<project_root>/node_modules/react-native/Libraries/Core/Devtools/setupDevtools.js` (module)
at ModuleMap._assertNoDuplicates (node_modules/jest-haste-map/build/module_map.js:128:11)
at Object.<anonymous> (node_modules/react-native/jest/setup.js:30:1)
Am I missing something here?
Also, when will this be fixed officially in here :(
I haven't encountered that, sorry. I'm away from my laptop on leave for two weeks so will have to have a look at it then. Hopefully the rewrite branch is ready by then anyway
Any updates on this?
you miss import PropTypes from 'prop-types';
Encountered this just now and I am using flow. Could it be an issue with flow, I have the latest version of Flow, Jest and RN
@Quadriphobs1
No, this library is no longer maintained and it doesn't work with React 15.5 and up because it uses deprecated React features.
I recommend checking out https://github.com/mfncooper/mockery.
Thanks @jdzak
@Quadriphobs1
Actually, I just realized mockery is no longer maintained. Jest has mocking functionality built in, that's probably worth checking out. https://jestjs.io/docs/en/manual-mocks
React.PropTypes is deprecated as of React v15.5. Please use the prop-types library instead
use the following
import PropTypes from 'prop-types';
Note: instead of using React.PropTypes.number use simply PropTypes.number