Comments (6)
Ahh, I remember the problem. By default, babel (of any kind) doesnt build any scripts that are inside the node_modules
directory. One way you could fix this is to mock the native-base
module, and just create some empty components, in the same way react-native-mock
does it. Or you can use the babel ignore
hook on require to compile just that folder (see here)
from react-native-mock.
No there is no mocking implementation with react-native-mock
that allows you to mock NativeModules
. The library I would recommend to achieve this is Mockery. There's some more talk on it over at #11
from react-native-mock.
Reading the stack trace, this is coming from a module called native-base
. You're solution would be correct. The easiest way to achieve this would be to either upgrade your version of node, as newer ones support import syntax, or you can use something like the babel-node package to do the conversion for you. But this is not a problem with react-native-mock
in any way, shape, or form :+1
from react-native-mock.
Yup, i agree this is not a react-native-mock's fault...but this will be a very common issue when trying to shallow test an 3rd party's Component that has import
keyword 😢
And I've tried all the approach that you have mentioned. My node version is 6.2.0
, which handles 96% compatible, but not working. Tried all kind of babel packages to but fail either.
from react-native-mock.
Hi @RealOrangeOne, I have a similar case in which I'm using a third party component (https://github.com/corymsmith/react-native-fabric/), while using react-native-mock.
When trying to run a test, I get
/Users/test/app/node_modules/react-native-fabric/Crashlytics.js:11
crash:SMXCrashlytics.crash,
TypeError: Cannot read property 'crash' of undefined
The code is
var { NativeModules, Platform } = require('react-native');
var SMXCrashlytics = NativeModules.SMXCrashlytics;
module.exports = {
crash: SMXCrashlytics.crash,
throwException: SMXCrashlytics.throwException,
.....
It fails because the mocked NativeModules doesn't know anything about a SMXCrashlytics, which is the expected behaviour.
Is it possible to hook into react-native-mock to include a mocked version of SMXCrashlytics (other than forking :) ) ?
from react-native-mock.
Closing as not an issue with react-native
. Best solution would be to run your tests using something like babel-node
so it builds your node_modules
, or to mock the library.
from react-native-mock.
Related Issues (20)
- React v15.5.0 Deprecation Warnings HOT 3
- Need a way to reset _animationFrame count HOT 2
- Mock for i18nManager HOT 3
- Missing support for percentage widths HOT 1
- Does it support mock fetch? HOT 3
- Invariant Violation: Native module cannot be null. HOT 6
- TypeError: Cannot read property 'number' of undefined HOT 23
- Cannot find module 'react/lib/ReactComponentTreeHook' from 'ReactDebugTool.js' HOT 35
- not able to install from npm HOT 6
- Plans to support FlatList HOT 1
- Should `babel-preset-airbnb` be in `dependencies`? HOT 1
- Warning: ReactTestUtils has been moved to react-dom/test-utils HOT 1
- Issue using via package manager since build is required HOT 6
- View.PropTypes is depricated but still used here. HOT 2
- emitting event from native ios working example
- Animated Delay is not exported HOT 1
- Animated is not fully mocked
- No wiki page now HOT 1
- Cannot find module 'ReactPerf' from 'react-native.js'
- Maintainers wanted HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from react-native-mock.