Suggest an editImprove this articleRefine the answer for “How to write a basic test in Jest?”. Your changes go to moderation before they’re published.Approval requiredContentWhat you’re changing🇺🇸EN🇺🇦UAPreviewTitle (EN)Short answer (EN)**A basic Jest test** follows the pattern: call the function through `expect(...)`, take its actual result and compare it with the expected value using the `toBe(...)` matcher inside `test(...)`. **Key point:** if the function returns the expected value the test is green; if not, Jest immediately shows an error and points to the mismatch.Shown above the full answer for quick recall.Answer (EN)ImageHere is a simple example of a basic unit test in **Jest**. --- ### **1. There is a regular function** `sum.js`: ```js function sum(a, b) { return a + b; } module.exports = sum; ``` --- ### **2. Write the test** `sum.test.js`: ```js const sum = require("./sum"); test("correctly adds two numbers", () => { expect(sum(2, 3)).toBe(5); }); ``` --- ### **3. Running the test** The `package.json` should have a script: ```json { "scripts": { "test": "jest" } } ``` Then in the terminal: ```javascript npm test ``` --- ### **What's happening here** - `test(...)` - describes the check - `expect(...)` - takes the actual result of the function - `toBe(...)` - compares it with the expected value If `sum(2, 3)` returns `5`, the test passes. If it returns anything else, Jest shows an error and points out where the mismatch is. --- That is a basic test: function → expected result → comparison.For the reviewerNote to the moderator (optional)Visible only to the moderator. Helps review go faster.