【问题标题】:Jest React Native how to test index.PLATFORM.jsJest React Native 如何测试 index.PLATFORM.js
【发布时间】:2018-02-09 15:10:35
【问题描述】:

如何对此进行测试,以获得 100% 的笑话覆盖率

// @flow
import { AppRegistry } from 'react-native'
import App from './src/App'


AppRegistry.registerComponent('app', () => App)

这种文件是'index.ios.js'和'index.android.js'

【问题讨论】:

    标签: reactjs testing react-native tdd jestjs


    【解决方案1】:

    新的 React Native 安装附带的默认测试应该按照您的需要进行。

    import 'react-native';
    import React from 'react';
    import Index from './index.PLATFORM.js';
    
    // Note: test renderer must be required after react-native.
    import renderer from 'react-test-renderer';
    
    it('renders correctly', () => {
      const tree = renderer.create(
        <Index />
      );
    });
    

    【讨论】:

    • 实际上它不适用于这种情况,并且有两个问题。 1) 文件没有导出组件。 2) () => 应用永远不会被调用
    猜你喜欢
    • 1970-01-01
    • 2020-10-26
    • 2023-04-11
    • 2022-06-11
    • 2016-07-22
    • 1970-01-01
    • 1970-01-01
    • 2021-04-24
    • 2018-01-29
    相关资源
    最近更新 更多