2017-10-04 3 views
0

まず、私はこの質問をする前に多くの人が検索して試したと言いたいと思います。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

私はReduxのフォームをテストする前にES5にコンパイルされていないと思います。

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

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

マイpackage.json冗談構成は次のようになりますように

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設定ファイルを検索します:よう

マイtest.test.jsに見えます

どのように正しく、これは、jest、どのようなエラーがないように構成する必要がありますか?

+0

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

すると、この作業を行います。たとえば、HelloWorldコンポーネントをtest.test.jsに追加し、これがレンダリングされるかどうかを確認します。 –

+0

jestファイルにそのモジュールをインポートしようとしましたか? – fungusanthrax

答えて

0

私はから私の部品の輸入を変更するために必要な:あなたは、単純なインラインコンポーネントの中に を置き換える場合

import { getFormValues} from "redux-form" 
関連する問題