2017-02-02 2 views
0

Я пытаюсь проверить приложение React Native с помощью Jest. Мое приложение использует несколько собственных модулей, и я даже не могу запустить начальный тест.Unit test React Собственное приложение, которое использует Native Modules with Jest

В моем приложении используется компонент 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

Это описано в JEST документации для среагировать-выходца сейчас:

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)/" 
] 

Существует также вопрос о GitHub в реакции нативным проекта, обсуждает этот вопрос: https://github.com/facebook/jest/issues/2382

Надеюсь, это поможет

Смежные вопросы