Why do I test JS apps, a thread
To start, I don’t enjoy writing tests _that much_

I don’t wake up in the morning and go “oh boy, I’m going to write some tests today!”

What I do enjoy is the value they give me, not the process
And I feel like that’s the key thing most people overlook - what kind of value are you getting out of tests

Do you need a significant test coverage on your toy project? Probably not

Do you need a crapton of tests on software that literally pays your salary? Yes. Yes you do.
(Of course all of this is based on my personal experience, your mileage may vary, some of you don’t write bugs but I do 😭)

I test my code because I don’t enjoy fixing it as soon as asap
If you’ve ever had a major production incident you know that “oh shit!” feeling

Fixing the bug in production environment is one thing but what’s more important for me is ensuring that it’s straight up IMPOSSIBLE to push a similar bug to prod again
These days I find myself writing more e2e tests than unit/integration ones

They’re closer to the user and after all users don’t care if your Apollo microservice cannot talk to Jupiter monolith

They just want to be able to edit a tweet or something
The more I think about it the less I’m convinced that test coverage is that much of good thing to measure

Of course - when it’s 0%-10% then you’re probably in trouble but is an app with 75% test coverage more resilient than one with 50%?
It’s impossible to measure but what I prefer to optimize for is confidence:

“How confident you are that feature X is not broken right now?”

Hint: manual tests performed when you launched it 3 months ago are simply not enough
Another thing that a well-tested codebase enables is a safer development cycle

If I see a complicated component with some logic (that the author probably understood when they were developing it) I’m not likely to refactor it if there are no tests

If it ain’t broken, why bother?
And again, that’s why I love e2e tests so much

You can literally replace all legacy jQuery plugins in your app with Svelte and if you did everything right - your tests will still pass

Therefore - the user experience remains the same *but* you get to write shiny new code
Poland has an official COVID app which is open sourced

I want you to guess how many tests their PWA has - hint: it’s the square root of 0

When I reported an issue asking them to add tests (because their form tells you if you’re in low/high risk group) they told me that...
“They didn’t have time to write tests”

And in my opinion, when working in large and/or important codebases (especially if they pay my salary) I don’t have the time NOT to test it and fix prod all the time

(Your mileage may vary)
You can follow @tlakomy.
Tip: mention @twtextapp on a Twitter thread with the keyword “unroll” to get a link to it.

Latest Threads Unrolled: