无法在jest react-navigation上读取导出的模块

时间:2017-04-23 15:03:21

标签: react-native jest react-navigation

我刚从导航中迁移,我的所有测试都在其中运行。我按照指南,阅读文档。该应用程序功能齐全,但我需要让测试工作。一切看起来都很好,但错误不会让我没有运行我的测试。似乎是转换时间的错误,模块未定义。但是我甚至无法记录导入包的值。

screen shot 2017-04-23 at 17 00 00

这是抛出的代码:

import { AppNavigator } from '../AppNavigator'

/*
** navigation
*/
export function navigation (state, action) {
  const nextState = AppNavigator.router.getStateForAction(action, state)
  return { ...state, ...nextState}
}

这是我导出AppNavigator的方式:

/**
* @providesModule %AppNavigator
* @flow
*/
import {
  StackNavigator,
} from 'react-navigation'

import { CloudAccount } from './containers/integrations/CloudAccount'
import * as Containers from './containers'

const routes = {
  Init: {
    screen: Containers.Init,
  },
  CloudAccount: {
    screen: CloudAccount,
  },
}

Object.keys(Containers).forEach(key => {
  routes[key] = {
    screen: Containers[key],
  }
})

export const AppNavigator = StackNavigator(routes, {
  headerMode: 'screen',
  navigationOptions: {
    gesturesEnabled: false,
    headerStyle: {
      backgroundColor: 'white',
      elevation: 1,
    },
    headerTitleStyle: {
      alignSelf: 'center',
    },
    headerBackTitle: null,
  },
  cardStyle: {
    backgroundColor: 'white',
  },
})

这是我的开玩笑配置:

  "jest": {
    "preset": "react-native",
    "transformIgnorePatterns": [
      "node_modules/(?!(jest-)?react-native|react-navigation)"
    ],
    "collectCoverageFrom": [
      "app/**/*.{js,jsx}",
      "!**/node_modules/**",
      "!**/tasks/**",
      "!**/meta/**",
      "!**/ios/**",
      "!**/app/lib/**"
    ],
    "coverageDirectory": "meta/coverage",
    "testEnvironment": "jsdom",
    "moduleNameMapper": {
      "^React$": "<rootDir>/node_modules/react"
    }
  },

我已经删除了node_modules,重新安装,删除了watchman并清理了cachés。有没有人有线索?

0 个答案:

没有答案