2

After updating my RN version, the test files are no longer passing. The following is one test that is failing and the corresponding error:

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')
})

And this is the error I get when I try to run it:

● 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)

I have seen some solutions with adding ignore patterns to my package.json file, but I have not been successful with those fixes. The tests ran fine until I updated the RN version and corresponding jest and babel packages.

1 Answers1

0

For those struggling with this issue, this link provides a partial fix:

React Native - Jest: Broken since update to 0.56. How to fix it?

From there, you may have to update certain tests since updating Babel tends to change syntax in their updates.