Unit and Integration Testing
- Unit tests. A unit test calls one function with known inputs and asserts the exact output: small, fast, and ruthless.
- Integration tests. An integration test exercises several parts together, catching the wiring mistakes unit tests cannot see.
- Arrange, act, assert. Readable tests keep three moves in order: arrange the world, act once, assert what must now be true.
Static Analysis and Linting
- Linting. A linter reads code without running it and flags likely bugs: unused variables, sloppy equality, unreachable branches.
- Formatting. A formatter rewrites style automatically so reviews argue about behaviour, never about commas.
- CI gates. Running lint and tests in CI on every change turns quality from a habit into a guarantee.
Designing Testable JavaScript
- Injecting dependencies. Pass collaborators in as parameters instead of reaching for globals, and tests can substitute them freely.
- Separating logic from effects. Keep calculations pure and push network and DOM work to the edges: the pure core tests in microseconds.
- Test doubles. A mock stands in for a real dependency, letting a test script the network’s answers and assert what was sent.
Before and after this level
- Before: Level 13: Runtime & Memory: Call Stack, Heap and Garbage Collection, References and Memory Behaviour, Finding Memory and Runtime Problems.
- Next: Level 15: Performance & Security: Performance Profiling, Common JavaScript Security Risks, Reliable Production Patterns.
In the app each of these ideas is taught and then asked back, and the level ends with a checkpoint and flashcards. See Checkpoints and flashcards.
Frequently asked questions
What does JavaScript Level 14: Testing & Code Quality cover?
Unit and Integration Testing, Static Analysis and Linting, Designing Testable JavaScript: 3 lessons and 9 ideas.
What should I know before this level?
The level before it, Level 13: Runtime & Memory, which covers Call Stack, Heap and Garbage Collection, References and Memory Behaviour, Finding Memory and Runtime Problems.