I have a simple test
import React from 'react';
import { shallow, mount, render } from 'enzyme';
import { CancelButton } from '../ClientApp/components/CancelButton';
describe('A suite', function() {
it('should render without throwing an error', function() {
expect(shallow(<CancelButton />).contains(<button className="btn btn-default"></button>)).toBe(true);
});
it('should be selectable by class "foo"', function() {
expect(shallow(<CancelButton />).contains(<button className="btn btn-default"></button>).toBe(true);
expect(shallow(<CancelButton />).is('.btn')).toBe(true);
});
it('should mount in a full DOM', function() {
expect(mount(<CancelButton />).find('.btn').length).toBe(1);
});
});
When I run the test I get
FAIL ClientApp/reactTests/CancelButton.test.js
● Test suite failed to run
\ClientApp\reactTests\CancelButton.test.js:1
({"Object.<anonymous>":function(module,exports,require,__dirname,__filename,global,jest){import React from 'react';
^^^^^
SyntaxError: Unexpected identifier
at ScriptTransformer._transformAndBuildScript (node_modules/jest-runtime/build/script_transformer.js:403:17)
I called this file CancelButton.test.js and placed it in reactTests folder. It seems that the JSX passed into the shallow function is not being recognized as JSX. I am getting errors around the '<' and normal "html: element syntax. I am not sure how to get around this in writing the test?