Jest is a JavaScript testing framework developed by Meta (Facebook). It is mainly used for testing JavaScript and TypeScript applications, especially React applications, but it also works well for Node.js backends.
// sum.js
function sum(a, b) {
return a + b;
}
module.exports = sum;
// sum.test.js
const sum = require('./sum');
test('addiert 1 + 2 und ergibt 3', () => {
expect(sum(1, 2)).toBe(3);
});
o run the test, use:
jest
Or, if installed locally in a project:
npx jest