jaimefps
jaimefps

Reputation: 2424

Jest testing error: Unexpected token <

Im trying to test my components with Jest. I believe that I've installed all the required modules to run the tests. Last thing that I did was to run

yarn add -D babel-plugin-transform-es2015-modules-commonjs.

This is my code while trying to do a simple Jest test:

import React, { Component } from 'react';
import { shallow } from 'enzyme';
import Market from '../src/components/Market.js';

test('Market should render as expected', () => {
  const component = shallow(<Market />);
  console.log(component);
});

The error message on the console points to the first < at the start of invoking the Market component on line 6.

Upvotes: 2

Views: 821

Answers (1)

Nipuna Marcus
Nipuna Marcus

Reputation: 223

I had the same issue. Adding transform or anything didn't fix it. So i finally added .babelrc file and added following configuration and it worked.

 {
    "presets": ["es2015", "react"]
 }

Hope this will help you.

Upvotes: 1

Related Questions