React native 更新为React Native 0.56.0后非项目文件中的Jest SyntaxError

React native 更新为React Native 0.56.0后非项目文件中的Jest SyntaxError,react-native,babel-jest,React Native,Babel Jest,更新我的RN版本后,测试文件不再通过。以下是一个失败的测试和相应的错误: import React from 'react' // Note: test renderer must be required after react-native. import renderer from 'react-test-renderer' import RelatedCallsListItem from '../app/components/Phoning/relatedCallsListItem' i

更新我的RN版本后,测试文件不再通过。以下是一个失败的测试和相应的错误:

import React from 'react'
// Note: test renderer must be required after react-native.
import renderer from 'react-test-renderer'
import RelatedCallsListItem from 
'../app/components/Phoning/relatedCallsListItem'
import {shallow} from 'enzyme'

const openItem = {
dueDate: '07/03/18',
subType: 'Follow-up',
subject: 'Test subject',
comment: 'Test comment',
dueTime: '',
date: '',
result: '',
isOpen: 'yes'
}

const completedItem = {
dueDate: '07/03/18',
subType: 'Follow-up',
subject: 'Test subject',
comment: 'Test comment',
dueTime: '',
date: '',
result: 'AppointmentMade',
isOpen: 'no'
}

it('renders properly', () => {
const item = openItem
expect(renderer.create(
    <RelatedCallsListItem item={item}/>
)).toMatchSnapshot()
})

it('notices the call is still open and there is a subType', () => {
const item = openItem
const test = shallow(
    <RelatedCallsListItem item={item}/>
)
console.log('test: ', test.debug())
expect(test.find('Text[testID="subType"]').prop('children')).toEqual('FOLLOW-UP')
})

it('notices the call is completed and there is a result', () => {
const item = completedItem
const test = shallow(
    <RelatedCallsListItem item={item}/>
)
console.log('test: ', test.debug())
expect(test.find('Text[testID="result"]').prop('children')).toEqual('APPT MADE')
})

我已经看到了一些将忽略模式添加到package.json文件的解决方案,但这些修复没有成功。在我更新RN版本以及相应的jest和babel软件包之前,测试运行良好。

对于那些正在解决此问题的人,此链接提供了一个部分修复:

从那以后,您可能必须更新某些测试,因为更新Babel会改变更新中的语法

● Test suite failed to run

Jest encountered an unexpected token

This usually means that you are trying to import a file which Jest cannot parse, e.g. it's not plain JavaScript.

By default, if Jest sees a Babel config, it will use that to transform your files, ignoring "node_modules".

Here's what you can do:
 • To have some of your "node_modules" files transformed, you can specify a custom "transformIgnorePatterns" in your config.
 • If you need a custom transformation specify a "transform" option in your config.
 • If you simply want to mock your non-JS modules (e.g. binary assets) you can stub them out with the "moduleNameMapper" config option.

You'll find more details and examples of these config options in the docs:
https://facebook.github.io/jest/docs/en/configuration.html

Details:

SyntaxError: /Users/fri0729/Desktop/PostingPlus/posting-plus/PostingPlus/node_modules/react-native/Libraries/StyleSheet/StyleSheet.js: Unexpected token (18:12)

  16 | const flatten = require('flattenStyle');
  17 | 
> 18 | import type {
     |             ^
  19 |   ____Styles_Internal,
  20 |   ____DangerouslyImpreciseStyle_Internal,
  21 |   ____DangerouslyImpreciseStyleProp_Internal,

  at Parser.raise (node_modules/@babel/core/node_modules/babylon/lib/index.js:776:15)
  at Parser.unexpected (node_modules/@babel/core/node_modules/babylon/lib/index.js:2079:16)
  at Parser.expectContextual (node_modules/@babel/core/node_modules/babylon/lib/index.js:2047:41)
  at Parser.parseImport (node_modules/@babel/core/node_modules/babylon/lib/index.js:5205:12)
  at Parser.parseStatementContent (node_modules/@babel/core/node_modules/babylon/lib/index.js:4043:27)
  at Parser.parseStatement (node_modules/@babel/core/node_modules/babylon/lib/index.js:3962:17)
  at Parser.parseBlockOrModuleBlockBody (node_modules/@babel/core/node_modules/babylon/lib/index.js:4513:23)
  at Parser.parseBlockBody (node_modules/@babel/core/node_modules/babylon/lib/index.js:4500:10)
  at Parser.parseTopLevel (node_modules/@babel/core/node_modules/babylon/lib/index.js:3938:10)
  at Parser.parse (node_modules/@babel/core/node_modules/babylon/lib/index.js:5304:17)