React Native-错误:找不到模块'StyleSheet'

时间:2018-08-29 14:32:28

标签: react-native mocha

我的应用程序本身运行良好。当我尝试实施导入我的App.js的摩卡单元测试时,出现以下错误:

Error: Cannot find module 'StyleSheet'

这可能是什么原因?下面是我如何在App.js

中导入StyleSheet的方法
import {
  StyleSheet, Text, View,
} from 'react-native';

StyleSheet中使用App.js

const styles = StyleSheet.create({
  container: {
    flex: 1,
    justifyContent: 'center',
    alignItems: 'center',
    backgroundColor: '#F5FCFF',
  },
  welcome: {
    fontSize: 20,
    textAlign: 'center',
    margin: 10,
  },
  instructions: {
    textAlign: 'center',
    color: '#333333',
    marginBottom: 5,
  },
});

test.js的完整代码

const assert = require('assert');
import { sum } from '../../App';
describe('Sum', function() {
    it('should return -1 when the value is not present', function() {
      function getRandomInt(max) {
        return Math.floor(Math.random() * Math.floor(max));
      }
      const firstInput = getRandomInt(10);
      const secondInput = getRandomInt(10);
      assert.equal(firstInput + secondInput, sum(firstInput, secondInput));
  });
});

1 个答案:

答案 0 :(得分:0)

不建议将Mocha用于测试React Native。它与Jest和Enzyme一起使用时效果更好。但是,如果您确实愿意,可以使用一些方法来避免这种情况。达到峰值hereherehere

相关问题