Unit testing React Native with Mocha and Enzyme
Ken Wheeler

Please see my previous comment on Mar 27th. I further had to change the conditional in compile.js to this in order to allow for a library in my node_modules dir importing React Native (e.g. react-native-video below):

if (
 fileName.indexOf(‘node_modules/react-native/Libraries/react-native/react-native.js’) >= 0 ||
 fileName.indexOf(‘node_modules/react-native-video/Video.js’) >= 0
 ) {

Otherwise, I saw this error:


(function (exports, require, module, __filename, __dirname) { import React from ‘react-native’;


SyntaxError: Unexpected token import

You’ll note this is a JS version issue and the compile.js logic is set up so that Video.js doesn’t make it to the babel transformer. However, if I coerce *any* file with JS > ES5 under react-native-video to make it to the babel transformer:

if (
 fileName.indexOf(‘node_modules/’) >= 0
 && fileName.indexOf(‘node_modules/react-native-video/’) === -1
 ) {

The resulting error:


var RCTVideo=requireNativeComponent(‘RCTVideo’,Video,{


TypeError: requireNativeComponent is not a function

The first solution however doesn’t produce this last error since the file gets transformed by babel *and* has access to the mock React object. And coercing all js files to go through the transformer causes issues with babel’s own files. So we probably need to come up with a more ideal long-term solution here.