Reputation: 1188
I'm trying to test a React Native component using jest and shallow rendering.
However, calls to ShallowRenderer.render()
results in an error
SyntaxError: Unexpected token ... at eval (native) at Object.eval (components/list-conditions.js:1:244) at Spec.eval (tests/components/list-conditions-test.js:14:48)
The test code is very simple, I don't even need to have an assert statement to get that error:
jest.dontMock('../../components/list-conditions.js');
const React = require('react');
const TestUtils = require('react-addons-test-utils');
const ListConditions = require('../../components/list-conditions.js');
describe('ListConditions', () => {
it('renders buttons', () => {
var renderer = TestUtils.createRenderer();
renderer.render(<ListConditions conditions={['a', 'b']} />);
});
});
Upvotes: 2
Views: 1302
Reputation: 138
I got the same Unexpected token error
, and adding a .babelrc
file in the project root file with the followings helps me
{
"presets": [
"react",
"es2015"
]
}
Upvotes: 1