-
Notifications
You must be signed in to change notification settings - Fork 20
Front End Testing With Jest
dlangston edited this page Dec 17, 2014
·
5 revisions
Painless JavaScript Unit Testing built on top of the Jasmine test framework.
-
Familiar Approach: Built on top of the Jasmine test framework, using familiar expect(value).toBe(other) assertions
-
Mock by Default: Automatically mocks CommonJS modules returned by require(), making most existing code testable
-
Short Feedback Loop: DOM APIs are mocked and tests run in parallel via a small node.js command line utility
Note: You will use npm to install Jest. If you don't have npm you can get it by installing node.js which includes npm.
To install Jest:
- Run
$ npm install jest-cli --save-dev
- Add the following to the
package.json
file.
{
...
"scripts": {
"test": "jest"
}
...
}
- Create a directory
__tests__/
.
- This is where you will keep your individual tests.
- Run
npm test
- You should see a result similar to this:
[PASS] __tests__/name-of-your-test.js (0.015s)
- https://facebook.github.io/jest/ Jest website
- http://facebook.github.io/react/docs/test-utils.html Test Utilities explained
- https://github.com/securingsincity/react-jest-example A React/Jest examples.
- http://jasmine.github.io/ Jasmine website.