Mocha测试React-Native抛出ReferenceError:__DEV__未定义

时间:2016-09-12 03:11:52

标签: react-native mocha atom-editor

我正在使用Atom和Mocha Test Runner。我得到ReferenceError:当我尝试针对React-Native(0.33)运行测试时,未定义 DEV

DEV 变量在各种react-native核心模块中被引用。

我的mocha测试跑步者选项包括: --compilers js:babel-register --opts test / mocha.opts --harmony-proxies test / setup.js

我的setup.js看起来像这样

import chai from "chai";
import fs from 'fs';
import path from 'path';
import register from 'babel-core/register';
import chaiEnzyme from 'chai-enzyme';

const modulesToCompile = [
  'react-native',
  'react-native-tabs',
  'react-native-vector-icons',
  'react-native-mock',
  'react-native-parallax-scroll-view'
].map((moduleName) => new RegExp(`/node_modules/${moduleName}`));

function getBabelRC() {
  var rcpath = path.join(__dirname, '..', '.babelrc');
  var source = fs.readFileSync(rcpath).toString();
  return JSON.parse(source);
}

var config = getBabelRC();

config.ignore = function(filename) {
  if (!(/\/node_modules\//).test(filename)) {
    return false;
  } else {
    const matches = modulesToCompile.filter((regex) => regex.test(filename));
    const shouldIgnore = matches.length === 0;
    return shouldIgnore;
  }
}

register(config);

global.__DEV__ = true;
global.expect = chai.expect;
chai.use(chaiEnzyme());

require('react-native-mock/mock');
const React = require('react-native')
React.NavigationExperimental = {
  AnimatedView: React.View
};

知道怎么处理这个吗?

1 个答案:

答案 0 :(得分:0)

看起来我在Mocha设置中删除了一个参数,它应该是

--compilers js:babel-register --opts test/mocha.opts --harmony-proxies --require test/setup.js