Jest:找不到模块内部需要testing的模块(相对path)

我有这个组件:

import React from 'react'; import VideoTag from './VideoTag'; import JWPlayer from './JWPlayer'; class VideoWrapper extends React.Component { //... component code } 

基于一些逻辑呈现另一个组件(VideoTag或JWPlayer),但当我试图在一个笑话文件中testing它,我得到的错误:

找不到模块'./VideoTag'

这三个组件都在同一个目录下,这就是为什么当我在浏览器中运行它并在运行时看到它实际工作的原因,但看起来Jest在解决这些相对path时遇到了问题,这是一个笑话文件:

 jest.dontMock('../src/shared/components/Video/VideoWrapper.jsx'); import React from 'react'; import ReactDOM from 'react-dom'; TestUtils from 'react-addons-test-utils'; import VideoWrapper from '../src/shared/components/Video/VideoWrapper.jsx'; describe('VideoWrapper tests', () => { it('Render JWPlayer', () => { let vWrapper = TestUtils.renderIntoDocument( < VideoWrapper model={model} /> ); }); }); 

错误是在线:

 import VideoWrapper from '../src/shared/components/Video/VideoWrapper.jsx'; 

我该如何告诉jest如何处理相对path?

这个问题不是path,它只是寻找扩展名为.js的模块,在jestconfiguration文件中添加.jsx后,它才工作:

 "moduleFileExtensions": [ "js", "jsx" ] 

由于jest使用['js','jsx','json','node']作为默认文件扩展名,因此您不需要在这两个选项的configuration中添加moduleFileExtensions。 (除非你想特别跳过任何选项)