【发布时间】:2018-05-11 10:37:02
【问题描述】:
我编写了一个小测试用例来测试ThankYouPage 组件,如下所示
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;
以下是开玩笑的测试用例-
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);
});
});
以下是我在运行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 | });
我是否缺少在浅层中解释 jsx 的依赖项?以下是我的部门的样子
"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"
}
【问题讨论】:
标签: javascript reactjs jestjs