Jest (JavaScript framework)

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.

gollark: I don't know. I don't think it's a significant amount but I don't have metrics on how often:- there actually is something like that going on/obviously visible, and nothing else happening in non-off-topic channels people actually discuss esolangs in- this is likely to make someone who may otherwise be an active member not be (I'd expect this is driven by other things)
gollark: Not sure if this is actually the case.
gollark: If it's nonjokingly we should maybe not do that then.
gollark: When did we actually *incite* violence?
gollark: It turns out that they are, but luckily I can't punch very hard.

See also

References

This article is issued from Wikipedia. The text is licensed under Creative Commons - Attribution - Sharealike. Additional terms may apply for the media files.