DEV Community

Discussion on: What was your TDD aha moment?

Collapse
 
mrbenj profile image
Ben Junya

For me to really get TDD, it all started off with building just a single function that did one stupid little thing.

Write the test for the function to get the expected value.
Watch it fail.
Make it pass by writing real code.
Make it fast.
Rinse and repeat.

Starting off with just building simple single function utilities really helped me understand TDD. Then as I started doing more React work and using the test renderer, my goals turned into:

Write the text to get 'x' rendering
Do all the previous steps.

Then I started using Enzyme's 'simulate' function... And so on... And so on...

If anything, I wouldn't say it was an "a-ha!" moment, but more of a pedagogical progression from small pieces to larger pieces.

I will admit that since I'm in the habit of doing this now, the modules, components, tools, any code that I write tends to be much smaller and highly testable.