【问题标题】:Mocha test React-Native throws ReferenceError: __DEV__ is not definedMocha 测试 React-Native 抛出 ReferenceError: __DEV__ is not defined
【发布时间】:2016-09-12 03:11:52
【问题描述】:

我正在使用 Atom 和 Mocha Test Runner。我收到 ReferenceError: DEV is not defined 当我尝试针对 React-Native (0.33) 运行测试时

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
};

知道如何处理吗?

【问题讨论】:

    标签: react-native mocha.js atom-editor


    【解决方案1】:

    好像我在Mocha设置中删除了一个参数,应该是

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-12-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-06-22
      • 2015-12-06
      • 2021-04-16
      • 1970-01-01
      相关资源
      最近更新 更多