Adding Some Math
Learn more about testing and the TDD test structure.
Next, we need to calculate how much of a project is remaining and the completion rate, and then put them together to determine a projected end date.
The next test is for the project to be able to calculate how much work is remaining.
TDD test structure
We like to take a moment before we write a test to think about what the test needs. The typical test structure has three parts:
-
Given: What data does the test need? This test needs a project, at least one complete task, and at least one incomplete task.
-
When: What action is taking place? We’re calculating the remaining work.
-
Then: What behavior do I need to specify? The work-calculation result.
Happy path test
We also like to think about what could make the happy-path test fail. That’s more helpful once we get the happy-path test in place and then start looking at it critically.
With that thought exercise over, we write our spec. There are two assertions, and we’ve split them up. We’d write them one at a time in practice, but we need to go through all those steps explicitly. To add this to the existing file, we wrap the specs that were already there in a describe
block and add this code as a second describe
block:
Get hands-on with 1400+ tech skills courses.