运行jest测试时意外的令牌导入

时间:2017-10-04 08:18:52

标签: javascript reactjs redux tdd jest

首先,我只想说在我提出这个问题之前我搜索并尝试了很多,我看到很多类似的主题,但是有人给了我一个答案。

我正在使用react,redux,redux-form,webpack,css-modules。

尝试使用jest测试我的项目,我收到此错误:

  

C:\ PROJECT \ node_modules \ Redux的形式\ ES \ getFormValues.js:1

     

从'./selectors/getFormValues'导入createGetFormValues;

     

^^^^^^ SyntaxError:意外的令牌导入

我认为在测试之前,redux-form不会编译为es5。

我的 test.test.js 看起来像是:

import React from 'react';
import {configure,render} from 'enzyme';
import Adapter from 'enzyme-adapter-react-15';

import TestComponent from '../../../components/TestComponent ';

describe('TestComponent ', () => {
    configure({adapter: new Adapter()});

    it('snapshot', () => {
        expect(render(<TestComponent/>)).toMatchSnapshot();
    });
});

我的 .babaelrc 配置文件如下所示:

{
  "presets": [
    "es2015",
    "react"
  ],
  "plugins": [
    "transform-class-properties",
    "transform-decorators",
    "transform-object-rest-spread"
  ]
}

我的package.json jest配置如下:

"jest": {
    "collectCoverageFrom": [
      "PROJECT/**/*.{js}"
    ],
    "moduleNameMapper": {
      "\\.(css|scss)$": "identity-obj-proxy"
    }
  }

如何正确配置,开玩笑,没有任何错误?

1 个答案:

答案 0 :(得分:0)

我需要更改我的组件的导入:

import getFormValuesfrom "redux-form\es\getFormValues";

import { getFormValues} from "redux-form"