Test Case
ELI5 — The Vibe Check
A test case is one specific scenario you want to check. 'Does the login work with a correct password?' — that's a test case. 'Does it fail with a wrong password?' — that's another test case. Each test() or it() block is one test case.
Real Talk
A test case is an individual test that verifies a specific behavior or scenario. It typically follows the AAA pattern: Arrange the preconditions, Act by calling the code under test, and Assert that the result matches expectations.
Show Me The Code
test('returns 404 when user not found', async () => {
// Arrange
const req = { params: { id: 'nonexistent' } };
const res = { status: jest.fn().mockReturnThis(), json: jest.fn() };
// Act
await getUser(req, res);
// Assert
expect(res.status).toHaveBeenCalledWith(404);
});
When You'll Hear This
"Write a test case for the empty cart scenario." / "This test case covers the happy path only."
Related Terms
AAA Pattern (AAA)
AAA stands for Arrange, Act, Assert.
Assertion
An assertion is your test saying 'I DEMAND this is true!'. It's you checking that the result is what you expected.
Edge Case
Edge cases are the weird, extreme, or unexpected inputs that trip up your code. What if someone types 0 for age?
Happy Path
The happy path is when everything goes perfectly — the user types the right thing, the API responds correctly, nothing breaks.
Test Suite
A test suite is just a collection of related tests grouped together.