Skip to content
This repository has been archived by the owner on Jun 3, 2024. It is now read-only.

TypeError: Cannot read property 'number' of undefined #139

Open
ToniChaz opened this issue Jun 16, 2017 · 23 comments · May be fixed by #158
Open

TypeError: Cannot read property 'number' of undefined #139

ToniChaz opened this issue Jun 16, 2017 · 23 comments · May be fixed by #158
Labels

Comments

@ToniChaz
Copy link

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"
  },
@RealOrangeOne RealOrangeOne changed the title TypeError: Cannot read property 'number' of undefine TypeError: Cannot read property 'number' of undefined Jun 18, 2017
@RealOrangeOne
Copy link
Owner

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.

@ToniChaz
Copy link
Author

ToniChaz commented Jun 19, 2017

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?

@RealOrangeOne
Copy link
Owner

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

@ToniChaz
Copy link
Author

Ok, thank you very much, I'll wait for the new version.

@gardner
Copy link

gardner commented Aug 18, 2017

@ToniChaz you can test out #140 by installing the latest commit from github: npm install --save-dev github:RealOrangeOne/react-native-mock#master

@mrdezzods
Copy link

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.

@dorraba
Copy link

dorraba commented Nov 13, 2017

Any expectations when it will be fixed?

@Parasrah
Copy link

Has anyone figured out a way around this besides downgrading react/react-native?

@waltermvp
Copy link

Any updated here?

@danReynolds
Copy link

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.

@msmaromi
Copy link

msmaromi commented Feb 8, 2018

@RealOrangeOne you should consider this

It should use the package prop-types to get the propTypes.

@deepaksasken
Copy link

@RealOrangeOne Any fix for this issue ? Im using latest RN v51 & React 16.

@gabrielrotbart
Copy link

I have a pull request that fixes this #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.

@PedramVeisi
Copy link

I have the same issue 😕

@saraht129
Copy link

@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 :(

@gabrielrotbart
Copy link

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

@janhesters
Copy link

Any updates on this?

@fakhri-arfaoui
Copy link

you miss
import PropTypes from 'prop-types';

@Quadriphobs1
Copy link

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

@jdzak
Copy link

jdzak commented Aug 22, 2018

@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.

@Quadriphobs1
Copy link

Thanks @jdzak

@jdzak
Copy link

jdzak commented Aug 24, 2018

@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

@praveenkumarkilari83
Copy link

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

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.