摩卡没有加载.jsx文件

时间:2016-08-26 11:01:53

标签: meteor reactjs mocha react-jsx jsx

我目前正在制作流星&反应项目,我想开始TDDing。到目前为止,我已经开发了一些使用摩卡的测试,一切都很好。但是,当我开始使用Enzyme测试React组件时,我尝试导入一个扩展名为.jsx的React组件,它只是无法加载它。这是我得到的错误:

W20160826-14:06:00.087(2)? (STDERR) Error: Cannot find module '../client/ui/component/internship/student-item.jsx'
W20160826-14:06:00.087(2)? (STDERR)     at require (packages/modules-runtime/.npm/package/node_modules/install/install.js:85:1)
W20160826-14:06:00.087(2)? (STDERR)     at meteorInstall.test.internship.test.js (test/internship.test.js:3:1)
W20160826-14:06:00.088(2)? (STDERR)     at fileEvaluate (packages/modules-runtime/.npm/package/node_modules/install/install.js:153:1)
W20160826-14:06:00.088(2)? (STDERR)     at require (packages/modules-runtime/.npm/package/node_modules/install/install.js:82:1)
W20160826-14:06:00.088(2)? (STDERR)     at /tmp/pablo/meteor-test-run6h5h3p/.meteor/local/build/programs/server/app/app.js:345:1
W20160826-14:06:00.089(2)? (STDERR)     at /tmp/pablo/meteor-test-run6h5h3p/.meteor/local/build/programs/server/boot.js:292:10
W20160826-14:06:00.089(2)? (STDERR)     at Array.forEach (native)
W20160826-14:06:00.090(2)? (STDERR)     at Function._.each._.forEach (/home/pablo/.meteor/packages/meteor-tool/.1.4.1_1.1vyh0jb++os.linux.x86_64+web.browser+web.cordova/mt-os.linux.x86_64/dev_bundle/server-lib/node_modules/underscore/underscore.js:79:11)
W20160826-14:06:00.090(2)? (STDERR)     at /tmp/pablo/meteor-test-run6h5h3p/.meteor/local/build/programs/server/boot.js:128:5

我看了一眼:Mocha will not recognise JSX但是没有解决我的问题。

我安装的软件包是:

  1. meteor add practicalmeteor:mocha
  2. npm i --save-dev react-addons-test-utils
  3. npm i --save-dev react-dom
  4. 之后我尝试安装其他一些包没有运气:

    • npm install --save-dev enzyme mocha chai chai-enzyme chai-jsx jsdom babel babel-core
    • npm install --save-dev babel-preset-es2015 babel-preset-react babel-preset-stage-0

    我的测试看起来像这样:

    import { Meteor } from 'meteor/meteor';
    import { mount, shallow } from 'enzyme';
    import StudentInternshipItem from '../client/ui/component/internship/student-item.jsx';
    
    if (Meteor.isClient) {
    
      describe('<StudentInternshipItem />', () => {
        it("contains spec with an expectation", function() {
          // this is empty cause I just want to check that the component is loaded before actually testing anything.
        });
      });
    
    }
    

    有人知道发生了什么吗?提前谢谢。

0 个答案:

没有答案