Current preferred testing framework as of 2017: Jest
Jest
Set up Jest
-
Install Jest
yarn add --dev jest
Or:
npm install --save-dev jest
-
Update package.json
"scripts": { "test": "jest"
-
If you wish to report coverage
-
Update package.json
"scripts": { "test": "jest --coverage"
-
Install coverage library
yarn add --dev coveralls
Or:
npm install --save-dev coveralls
-
Make sure linter ignores coverage folder
-
Point eslint to specific folder
"scripts": { "lint": "eslint src/*",
-
Or, add coverage to .eslintignore
-
-
- Configure linter for Jest
- Add this to your .eslintrc or .eslintrc.js:
"env": { "jest": true,
- Add this to your .eslintrc or .eslintrc.js:
-
Run jest to make sure it’s working
yarn test
Or:
npm test
-
Create your first test
-
In the same folder as the Javascript file you want to test, create a
__tests__
folder -
Create a tests file with the same name as the Javascript file you’re testing, but with a .test.js extension
-
Write your test
https://facebook.github.io/jest/docs/en/getting-started.html
-