Skip to content
AgileLogics
5 min read

Testing

Prerequisites: Functions

Jest is one of the most common testing tools in JavaScript (npm install --save-dev jest). A test file checks expected behavior with expect(...) assertions.

// calculator.js
export function add(a, b) {
    return a + b;
}
// calculator.test.js
import { add } from "./calculator.js";

test("adds two numbers", () => {
    expect(add(2, 3)).toBe(5);
    expect(add(-1, 1)).toBe(0);
});
npx jest

Running jest automatically finds every *.test.js file in the project and reports which passed or failed.