Assertion
ELI5 — The Vibe Check
An assertion is your test saying 'I DEMAND this is true!'. It's you checking that the result is what you expected. If it's not, the test fails and the assertion screams at you. It's the actual checking part of a test.
Real Talk
An assertion is a statement in a test that verifies a specific condition is true. If the assertion fails, the test fails. Assertion libraries (like Chai, Jest's expect, or Node's assert module) provide expressive APIs to compare values, check types, and verify behavior.
Show Me The Code
// Different assertion styles
expect(result).toBe(42); // strict equality
expect(result).toEqual({ name: 'Alice' }); // deep equality
expect(fn).toThrow(Error); // throws check
expect(arr).toHaveLength(3); // length check
expect(str).toContain('hello'); // substring check
When You'll Hear This
"Your test has no assertions — it will always pass!" / "Add an assertion to check the response status code."
Related Terms
AAA Pattern (AAA)
AAA stands for Arrange, Act, Assert.
Chai
Chai is an assertion library that makes your test checks read like English. Instead of `assert.equal(x, 5)` you can write `expect(x).to.
Jest
Jest is the most popular JavaScript testing framework.
Test Case
A test case is one specific scenario you want to check. 'Does the login work with a correct password?' — that's a test case.
Unit Test
A unit test is like checking that one single LEGO brick isn't broken before you use it in your big castle.