Jump to content

Draft:Jest (framework)

From Wikipedia, the free encyclopedia

This is an old revision of this page, as edited by Lyokolux (talk | contribs) at 11:35, 14 August 2020 (Add svelte in the list of support framework). The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.

Jest[1] is a JavaScript testing framework maintained by Facebook, Inc. with a focus on simplicity. It works with projects using: Babel, TypeScript, Node.js, React, Angular, Vue.js and Svelte. It aims to work out of the box and config free.

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);
});
module.exports = sum;

Then, from the command line, run the command

$ npm run test

This runs the test and outputs the corresponding result in your command line.

See also

References

  1. ^ "Jest Website".