I have written a small test case to test a ThankYouPage component which looks like below
import ToggleDisplay from 'react-toggle-display';
import styles from '../styles.css';
function ThankYouPage(props) {
return (
<ToggleDisplay show={props.show}>
<div className={styles.thankyouText}> Thank you!</div>
<div className={styles.helpText}>
The more you thanks, the better.
</div>
</ToggleDisplay>
);
}
export default ThankYouPage;
Following is the test case in jest -
import React from 'react';
import ThankYouPage from './components/thank-you-page';
import { shallow } from 'enzyme';
describe('<ThankYouPage />', () => {
it('renders 1 ThankYouPage component', () => {
const component = shallow(<ThankYouPage show=true />);
expect(component).toHaveLength(1);
});
});
Following is the trace on console I get after running npm test
> myreactapp@1.0.0 test /Users/rahul/myreactapp
> jest
FAIL tests/thank-you-page.test.js
● Test suite failed to run
/Users/cominventor/myreactapp/tests/thank-you-page.test.js: Unexpected token (8:30)
6 | describe('<ThankYouPage />', () => {
7 | it('renders 1 ThankYouPage component', () => {
> 8 | const component = shallow(<ThankYouPage show=true />);
| ^
9 | expect(component).toHaveLength(1);
10 | });
11 | });
Am I missing a dependency to interpret jsx within shallow? Following is how my deps look like
"devDependencies": {
"babel-jest": "^22.4.3",
"oc-template-react-compiler": "5.0.2",
"prettier": "^1.10.2",
"prettier-eslint": "^8.8.1"
},
"dependencies": {
"axios": "^0.18.0",
"enzyme": "^3.3.0",
"jest": "^22.4.3",
"jsdom": "^11.10.0",
"querystring": "^0.2.0",
"react-cookie": "^2.1.4",
"react-scripts": "^1.1.4",
"react-toggle-display": "^2.2.0"
}