Jest test Function
Question
What does the test() function do in Jest?
Hint
test(name, fn) is the basic building block of Jest tests.
Explanation
The test() function (alias: it()) defines a test case in Jest. Syntax: test("description", () => { expect(value).toBe(expected); }). The first argument is a descriptive name (shown in output). The second is a function containing assertions. test.skip skips the test. test.only runs only this test. test.todo marks a test as not yet implemented. Group related tests with describe(). The test name should describe the behavior being tested, not the implementation. Good names: "returns sum of two numbers", "throws on invalid input".
Related Resources
Related Lessons
- Jest Basics
Learn Jest.
Look up unfamiliar terms
A beginner-friendly glossary explains jargon in plain English — variables, functions, DOM, Promise, and more.
Decode error messages
Plain-English explanations of common errors — what they mean, why they happen, and how to fix them.
Build real projects
Apply what you learned by building guided projects with starter code and solutions.