TDD in Node.js 🇵🇱 🇬🇧 1-2 days
TDD - a practice, a tool, a strategy to develop software
It helps to stay focused and design good APIs in the micro scale. As any other tool or practice it works in certain contexts.
In 2 days you'll learn to design Node.js apps with tests.
We'll be practicing so-called London School of TDD aka outside-in development.
On day 1 day we test drive command-line app for data processing (pipes and filters pattern).
On day 2 we test drive REST API with Express.js and MongoDB.
The size of our problem is about 150 lines of production code and 300 lines of test code for each app.
What will I learn?
- Design clean and testable code driven by small, focused tests
- Look at your tests with ROI in mind, how to avoid testing the same things over and over again
- Design testable code with "difficult" dependencies such as file system, HTTP or stdout
- Choose effective strategies for testing async code
- Complement tactical decisions from TDD with strategic decision on the whiteboard
- Gather necessary feedback from design spikes
- Listen to feedback from tests and adjust code structure accordingly
- Replace (mocking) libraries and tools with practices and techniques available in Vanilla JS
- Better communicate intent with new ES6 language constructs and better decide when to use them
- Use some of the less explored idioms from OO and FP to maximize your options and go beyond thisful/class based school of programming
- Question mainstream tools and practices (e.g. why I rarely use libraries like nock/sinon/chai and why DRY is sometimes overrated)
- Practice, tool, strategy - looking at TDD from different perspectives
- TDD as a tactical tool to design simple APIs in the micro scale
- TDD and strategic decisions - how TDD and whiteboard supplement each other
- Spike - getting to know the shape of the problem
- ROI from tests
- tests as feedback mechanism to improve code
- unit vs integration tests - practical examples showing which test to choose
- happy path vs unhappy path - testing exceptional situations and corner cases
- comparison of London School of TDD vs Detroit/Chicago school of TDD
- file system
- HTTP client
- test doubles: mock, spy, stub
- managing test data in database integration tests
- Designing testable async APIs
- Promises and async/await in tests
TDD and FP
- thinking in terms of data flow
- higher order functions
- pure functions
- programming without this/class/prototype
- how to minimise the usage of testing tools and use the language instead
- Node assert