简体   繁体   English

开玩笑测试:无法从'Link.react.js'中找到模块'../Link.react'

[英]Jest test: Cannot find module '../Link.react' from 'Link.react.js'

I am trying to setup jest test following https://jestjs.io/docs/en/tutorial-react I have installed the jest related dependencies, created __test__/link.react.test.js and Link.react.js . 我试图在https://jestjs.io/docs/en/tutorial-react之后设置jest测试我已经安装了与jest相关的依赖项,创建了__test__/link.react.test.jsLink.react.js Following is my structure: 以下是我的结构: 在此输入图像描述

However, it has problem for the test as following. 但是,测试存在如下问题。 But My structure and two files are exactly same as the tutorial. 但我的结构和两个文件与教程完全相同。

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', () => {

Change file name from Link.react.js to Link.js . 将文件名从Link.react.js更改为Link.js And change in the link.react.test.js file the path to Link . 并在link.react.test.js文件中更改Link的路径。 Sorry, I don't know exactly why it will work :) 对不起,我不知道为什么它会起作用:)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 无法从'ReactTestUtils.js'找到模块'react / lib / React' - Cannot find module 'react/lib/React' from 'ReactTestUtils.js' Jest 无法从“src/tests/X.test.ts”中找到打字稿模块“../X.js” - Jest cannot find typescript module '../X.js' from 'src/tests/X.test.ts' 无法从“ReactDebugTool.js”中找到模块“react/lib/ReactComponentTreeHook” - Cannot find module 'react/lib/ReactComponentTreeHook' from 'ReactDebugTool.js' 错误:找不到模块“react-dom/test-utils” - Error: Cannot find module 'react-dom/test-utils' 错误:在 next.js 中找不到模块“swiper/react” - Error: Cannot find module 'swiper/react' in next.js 与 webpack 的 npm 链接 - 找不到模块 - npm link with webpack - cannot find module 使用 Moment JS 创建 React-App:找不到模块“./locale” - Create-React-App with Moment JS: Cannot find module “./locale” react-select 模块找不到 react - The react-select module cannot find react browserify + gulp + react无法找到模块反应 - browserify + gulp + react cannot find module react 浏览器控制台错误:无法从“ react / lib / ReactAddonsDOMDependencies.js”中找到模块“ react-dom / lib / ReactPerf” - Browser Console error: Cannot find module 'react-dom/lib/ReactPerf' from 'react/lib/ReactAddonsDOMDependencies.js'
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM