1

对于使用 react-router、jest 和 react-test-renderer 的 react-native 应用程序,该<Link>组件似乎不可测试。react-router 文档没有提到必须为 react-native 做任何特别的事情(模拟?),我的测试只有在 react-router 的组件包含在正在渲染的树中时才会爆炸<Link>。其他组件(例如<Text>, <Router>)没有这个问题。

这个基本的 react-native 项目重现了爆炸测试。否则,该应用程序会在手机内部按预期构建和运行。

我有配置问题吗?它是无证的,还是我只是忽略了它?还是我应该放弃并改用酶?那会有帮助吗?

这是显着的测试输出:

  TypeError: Cannot read property 'default' of undefined
      at new Link (minimal-bug-repro/node_modules/react-router-native/Link.js:5:379)
      at constructClassInstance (minimal-bug-repro/node_modules/react-test-renderer/cjs/react-test-renderer.development.js:3438:22)                                                                                                                                
      at updateClassComponent (minimal-bug-repro/node_modules/react-test-renderer/cjs/react-test-renderer.development.js:6764:9)                                                                                                                                   
      at beginWork (minimal-bug-repro/node_modules/react-test-renderer/cjs/react-test-renderer.development.js:7721:20)
      at performUnitOfWork (minimal-bug-repro/node_modules/react-test-renderer/cjs/react-test-renderer.development.js:11392:16)                                                                                                                                    
      at workLoop (minimal-bug-repro/node_modules/react-test-renderer/cjs/react-test-renderer.development.js:11424:28)
      at renderRoot (minimal-bug-repro/node_modules/react-test-renderer/cjs/react-test-renderer.development.js:11507:11)                                                                                                                                           
      at performWorkOnRoot (minimal-bug-repro/node_modules/react-test-renderer/cjs/react-test-renderer.development.js:12395:11)                                                                                                                                    
      at performWork (minimal-bug-repro/node_modules/react-test-renderer/cjs/react-test-renderer.development.js:12307:11)                                                                                                                                          
      at performSyncWork (minimal-bug-repro/node_modules/react-test-renderer/cjs/react-test-renderer.development.js:12281:7) { componentStack:                                                                                                                     
4

1 回答 1

0

将 jest 升级到 >= 24.0.0,删除 jest.config.js 的transform:部分,然后切换到普通的preset: 'react-native'.

于 2019-03-28T04:49:18.287 回答