2016-11-29 13 views
0

私はReact NativeプロジェクトにJest Testingフレームワークを追加しています。私は次のエラーを取得しています:冗談構成

Failed to get mock metadata: /Users/me/Documents/Development/project/node_modules/global/window.js 

私のテストファイルは次のようになります。

"jest": { 
    "preset": "jest-react-native", 
    "testPathIgnorePatterns": ["/node_modules/", "/example/", "/lib/"], 
    "testRegex": "(/tests/.*|\\.(test|spec))\\.(js|jsx)$", 
    "automock": "true", 
    "unmockedModulePathPatterns": [ "lodash" ], 
    "transformIgnorePatterns": [ 
     "node_modules/([email protected]/ex-navigation", 
     ")" 
    ] 
    } 

私が持っていた:また

import 'react-native' 
import React from 'react' 
import { MyComponent } from '../components/MyComponent' 

import renderer from 'react-test-renderer' 

it('renders correctly',() => { 
    const tree = renderer.create(<MyComponent />).toJSON() 
    expect(tree).toMatchSnapshot() 
}) 

そして、私のpackage.jsonで冗談設定

プロンプトが表示されたら、 http://facebook.github.io/jest/docs/manual-mocks.html#contentを見てください。あなたのpackage.jsonで

答えて

0

セット"automock": "false"(とautomocking冗談反応するネイティブisn't supportedプリセット)

1

私は何かがpackage.jsonであなたの冗談の設定が間違っていると思います。ここ

は、サンプル冗談の設定の断片である:

"jest": { 
    "preset": "react-native", 
    "cacheDirectory": "./cache", 
    "coveragePathIgnorePatterns": [ 
     "./app/utils/vendor" 
    ], 
    "coverageThreshold": { 
     "global": { 
     "statements": 80 
     } 
    }, 
    "transformIgnorePatterns": [ 
     "/node_modules/(?!react-native|react-clone-referenced-element|react-navigation)" 
    ] 
    } 

プリセット:プリセットが反応ネイティブアプリの環境を模倣ノード環境です。 DOM APIまたはブラウザAPIはロードされないため、Jestの起動時間が大幅に向上します。

cacheDirectory:テスト速度を大幅に向上させるのに役立ちます。コンパイルされたモジュールのキャッシュを作成することで、次回はテスト実行中にnode_moduleをコンパイルする必要がなくなります。

coveragePathIgnorePatterns:カバレッジレポートをスキップするファイルを定義します。

coverageThreshold:渡すすべてのテストのしきい値を定義します。カバレッジが定義された制限よりも小さい場合、テストは失敗します。これにより、いつでも十分なカバレッジを保つことができました。

transformIgnorePatterns:ここでは、NPMモジュールをすべて転送する必要があります。これらのモジュールは基本的にES6/7モジュールです。

PS:私はリアクションネイティブプロジェクトのための冗談を設定する方法についてのブログを書いています。 URLは次のとおりです。http://rahulgaba.com/react-native/2017/05/19/Jest-test-suite-with-superpowers.html

関連する問題