Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/andrewrunner/tdd-jest-practice
My experiments with jest test library (use pure http server on node.js)
https://github.com/andrewrunner/tdd-jest-practice
jest nodejs tdd typescript
Last synced: about 1 month ago
JSON representation
My experiments with jest test library (use pure http server on node.js)
- Host: GitHub
- URL: https://github.com/andrewrunner/tdd-jest-practice
- Owner: andrewrunner
- Created: 2023-12-02T16:58:03.000Z (about 1 year ago)
- Default Branch: main
- Last Pushed: 2024-02-05T10:22:39.000Z (about 1 year ago)
- Last Synced: 2024-11-10T20:08:25.666Z (3 months ago)
- Topics: jest, nodejs, tdd, typescript
- Language: TypeScript
- Homepage:
- Size: 256 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# ex-jest-first-steps
My experiments with Jest test library
1. AAA principles (ARRANGE-ACT-ASSERT)
2. F.I.R.S.T. principles (Fast, Independent, Repitable, Self-validating, Thorough)Use
- VSCode "REST Client" extension for run .http files
- https://github.com/microsoft/vscode-recipes/tree/main/debugging-jest-testsJest hooks can help init common mocks for all tests;
Principles:
- One class = one test case.
- One method = one or more tests.
- One alternative branch (if/switch/try-catch/exception) = one test.Doubles:
- Dummy object
- Fakes
- Stubs
- Spiec
- MocksHeavy mock testing approach
Advantages:
- Test classes in isolation
- Impose a strict coding style (If class has too many dependencies - it makes it hard to test...)
- Once tests are in place, it easy to create new tests
Disadvantages:
- Test and implementation are tighly coupled (small change leads to many changes)
- Hard to writeMike Cohn's pyramid tests consist of three levels (from bottom to top):
- Unit tests.
- Service tests.
- User interface tests.
In this pyramid, the main rule consists of two principles:The higher the level, the fewer tests.