2017-10-04 143 views
0

首先我想說的是,在我問這個問題之前,我搜索並試了很多,我看到很多simillar主題,但任何人都給我一個答案。當運行jest測試時意外的令牌導入

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

並嘗試通過使用笑話來測試我的項目,我得到這個錯誤:

C:\PROJECT\node_modules\redux-form\es\getFormValues.js:1

import createGetFormValues from './selectors/getFormValues';

^^^^^^ SyntaxError: Unexpected token import

我認爲,終極版型不編譯測試之前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": { 
    "collectCoverageFrom": [ 
     "PROJECT/**/*.{js}" 
    ], 
    "moduleNameMapper": { 
     "\\.(css|scss)$": "identity-obj-proxy" 
    } 
    } 

我該如何正確配置這個,開玩笑,沒有任何錯誤?

+0

這是否工作,如果你更換一個簡單的在線組件中。例如,將一個HelloWorld組件添加到test.test.js中,並查看它是否呈現。 –

+0

您是否簡單地嘗試在該jest文件中導入該模塊? – fungusanthrax

回答

0

我需要改變從我的組件的進口:

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

import { getFormValues} from "redux-form" 
相關問題