Building Testing Intuition
I was going to release an article about testing React components, but I realized that I was missing something. Something that's important when going about the task of writing tests.
I know that sounds pretty nebulous, but despite all my research into the best practices for testing React components, I still found myself lost. What do you test? What isn't important to test, and what is absolutely critical? Is there such a thing as too much testing? Or will there never be enough tests? How do you write your tests so you can get the most value out of them?
There's a lot of debate from a lot of intelligent and practiced people out there about these questions. After watching a lot of talks and tutorials, and reading many more Medium articles, blog posts, and how-to's, I've learned one big thing:
What, and how, you test depends on how many times you've fucked up.
This seems like an odd take away, doesn't it? Shouldn't there be something more insightful about partitioning, or validating edge cases? As far as I've gathered, that's a matter of academic discussion - and I don't have the patience for that kind of rigorous thought when all I want to do is implement the next feature.
Instead, it seems, what is more important for those of us who aren't (yet)
Kent Dodds testing gurus, is to write lots of tests. Lots of shitty,
useless tests. We should write so many shitty tests that we start to hate
ourselves for writing these useless tests and start to think about why these
tests are so shit.
And that's when the magic happens. That's when we start to build a foundation, an intuition, about what and how to test. I hate that there's no magic formula, no golden rule of thumb. But it's what it is, and, like most things in life, we only get better when we fail.
So I'm going to spend the next month writing as many, shitty React component tests I can to see if I can figure out a formula that works for me. I'd like to challenge you to do the same. It doesn't have to be React component tests, but if you're stuck on something and can't find a solution that Just Works, give it your best shot. Try so many shit solutions you can't help but wonder why their shit. And maybe, just maybe, you'll figure it out.