Test-Driven Development
Explore the principles of test-driven development (TDD) within a TypeScript functional programming context. Learn to write tests before code, build functions iteratively, and ensure high test coverage. Understand TDD's benefits for code quality, refactoring, and thoughtful functionality design.
We'll cover the following...
Perhaps a brief explanation of that concept is in order. Test-driven development (TDD) comes from the Extreme Programming movement. Its core idea is to create a test that verifies the code’s behavior before actually writing that code. Let’s write a function that adds two numbers.
Writing test
Before writing code, we’ll create the following test using the Jest framework:
Obviously, this test fails because we lack a function that adds numbers. We don’t even have a sum yet. Our first step is to compile our ...