Draft:Jest (framework)

From English Wikipedia @ Freddythechick

Jest[1] is a JavaScript testing framework built on top of Jasmine[2] and maintained by Meta (formerly Facebook). It was 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 doesn't require a lot of configuration for first-time users of a testing framework.

Usage and examples

Installation

Use the JavaScript package manager npm to install Jest in Node.js:<syntaxhighlight lang="bash"> $ npm install --save-dev jest </syntaxhighlight>

Example

In this example, we will write a test case for the following module saved as sum.js: <syntaxhighlight lang="javascript"> function sum(a, b) {

 return a + b;

}

module.exports = sum; </syntaxhighlight>

Our test case will be in a file named sum.test.js for Jest to automatically pick it up as a test case for sum.js.

The contents of the file with the test case will be:

<syntaxhighlight lang="javascript"> const sum = require('./sum');

test('adds 1 + 2 to equal 3', () => {

 expect(sum(1, 2)).toBe(3);

}); </syntaxhighlight>

Then, from the command line, we run this command:

<syntaxhighlight lang="bash"> $ npm run test </syntaxhighlight>

This runs the test and outputs the corresponding result on the command line.

See also

References

  1. ^ "Jest Website".
  2. ^ "jest/README.md at 88a94d5d1bc1f387317a3068bf510ab992c5dc64 · facebook/jest". GitHub. Retrieved 2022-05-31.

External links

Category:JavaScript libraries Category:JavaScript programming tools Category:Software using the MIT license Category:JavaScript web frameworks