【问题标题】:Jest test: Cannot find module '../Link.react' from 'Link.react.js'开玩笑测试:无法从“Link.react.js”中找到模块“../Link.react”
【发布时间】:2019-02-22 16:50:44
【问题描述】:

我正在尝试在https://jestjs.io/docs/en/tutorial-react 之后设置玩笑测试我已经安装了玩笑相关的依赖项,创建了__test__/link.react.test.jsLink.react.js。以下是我的结构:

但是,它有以下测试问题。但我的结构和两个文件与教程完全相同。

FAIL  __tests__/link.react.test.js
  ● Test suite failed to run

    Cannot find module '../Link.react' from 'Link.react.js'

       5 | 
       6 | import React from 'react';
    >  7 | import Link from '../Link.react';
         | ^
       8 | import renderer from 'react-test-renderer';
       9 | 
      10 | it('renders correctly', () => {

【问题讨论】:

  • 您可以尝试将文件名从Link.react.js 更改为Link.js。并在link.react.test.js文件中更改Link的路径
  • 有效!您能否请帖作为答案,我会接受。但是很奇怪,教程使用相同的文件名并且教程有效!我想知道你是否知道原因
  • 这只是我的直觉建议。我认为系统无法识别文件扩展名是js,因为文件名中有.react

标签: node.js reactjs jestjs


【解决方案1】:

将文件名从 Link.react.js 更改为 Link.js。并在link.react.test.js 文件中更改Link 的路径。抱歉,我不知道它为什么会起作用:)

【讨论】:

    猜你喜欢
    • 2017-12-19
    • 2020-12-21
    • 2021-05-30
    • 2021-01-01
    • 2019-03-26
    • 1970-01-01
    • 2017-11-28
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多