2017-02-02 4 views
0

JestでReactネイティブアプリをテストしようとしています。私のアプリはいくつかのネイティブモジュールを使用しており、私は最初のテストを実行することすらできません。ユニットテストReactネストでネイティブモジュールを使用するネイティブアプリ

私のアプリはネイティブの依存関係を持つコンポーネントreact-native-cameraを使用しています。

最初のテスト:私はそれを実行すると

import 'react-native'; 
import React from 'react'; 
import Index from '../index.ios.js'; 

// Note: test renderer must be required after react-native. 
import renderer from 'react-test-renderer'; 

it('renders correctly',() => { 
    const tree = renderer.create(
    <Index /> 
); 
}); 

、私は次のエラーを取得する:

FAIL __tests__/index.android.js
● Test suite failed to run

TypeError: Cannot read property 'Aspect' of undefined 

    at Object.<anonymous> (node_modules/react-native-camera/index.js:250:78) 

にはどうすればネイティブモジュールによって、エラーの原因のこのタイプをバイパスすることができますか?浅いレンダリングかこれに類するもの?

私はRN 0.39を使用します。

おかげ

答えて

0

それは反応し、ネイティブ今の冗談のドキュメントで説明しています:反応-ネイティブプロジェクト内githubの上の問題こともあり

https://facebook.github.io/jest/docs/tutorial-react-native.html#transformignorepatterns-customization

The transformIgnorePatterns option can be used to whitelist or blacklist files from being transformed with babel. Many react-native npm modules unfortunately don't pre-compile their source code before publishing.

By default the jest-react-native preset only processes the project's own source files and react-native. If you have npm dependencies that have to be transformed you can customize this configuration option by whitelisting modules other than react-native:

"transformIgnorePatterns": [ 
    "node_modules/(?!react-native|my-project|react-native-button)/" 
] 

この問題について説明します:https://github.com/facebook/jest/issues/2382

これが役に立ったらいいですか

関連する問題