Jest (JavaScript framework)
Jest[1] is a JavaScript testing framework maintained by Facebook, Inc. designed and built by Christoph Nakazawa with a focus on simplicity and support for large web applications. It works with projects using Babel, TypeScript, Node.js, React, Angular, Vue.js and Svelte. Jest does not require a lot of configuration for first time users of a testing framework.
Usage and examples
$ npm install --save-dev jest
For the following module, we will write a corresponding test case:
function sum(a, b) {
return a + b;
}
module.exports = sum;
If the above file was named sum.js, we will write our test case in a file named sum.test.js for Jest to automatically pick it up. The contents of the file will be:
const sum = require('./sum');
test('adds 1 + 2 to equal 3', () => {
expect(sum(1, 2)).toBe(3);
});
Then, from the command line, run the command
$ npm run test
This runs the test and outputs the corresponding result on the command line.