This project was bootstrapped with Create React App.
-
- 在src目录下新建一个
setupTests.js
里面引入enzyme的配置和react适配器
- 在src目录下新建一个
import { configure } from 'enzyme'
import Adapter from 'enzyme-adapter-react-16
configure({ adapter: new Adapter })
-
- 在containers 和 components目录下 各 新建一个
__test__
的目录
- 在containers 和 components目录下 各 新建一个
-
- 然后在__test__目录下新建与组件名相同并且加.test.js结尾的文件 如:
Home.test.js
orHelloWorld.test.js
注意:名字必须和组件名一致
- 然后在__test__目录下新建与组件名相同并且加.test.js结尾的文件 如:
-
- 测试文件中先引入enzyme 的方法
import { shallow } from 'enzyme';
const wrapper = shallow(<MyComponent />);
In the project directory, you can run:
Runs the app in the development mode.
Open http://localhost:3000 to view it in the browser.
The page will reload if you make edits.
You will also see any lint errors in the console.
Launches the test runner in the interactive watch mode.
See the section about running tests for more information.
Builds the app for production to the build
folder.
It correctly bundles React in production mode and optimizes the build for the best performance.
The build is minified and the filenames include the hashes.
Your app is ready to be deployed!
Note: this is a one-way operation. Once you eject
, you can’t go back!
You can learn more in the Create React App documentation.
To learn React, check out the React documentation.
This section has moved here: https://facebook.github.io/create-react-app/docs/code-splitting
This section has moved here: https://facebook.github.io/create-react-app/docs/analyzing-the-bundle-size
This section has moved here: https://facebook.github.io/create-react-app/docs/making-a-progressive-web-app
This section has moved here: https://facebook.github.io/create-react-app/docs/advanced-configuration
This section has moved here: https://facebook.github.io/create-react-app/docs/deployment
This section has moved here: https://facebook.github.io/create-react-app/docs/troubleshooting#npm-run-build-fails-to-minify