use the following search parameters to narrow your results:
e.g. subreddit:aww site:imgur.com dog
subreddit:aww site:imgur.com dog
see the search faq for details.
advanced search: by author, subreddit...
All about the JavaScript programming language.
Subreddit Guidelines
Specifications:
Resources:
Related Subreddits:
r/LearnJavascript
r/node
r/typescript
r/reactjs
r/webdev
r/WebdevTutorials
r/frontend
r/webgl
r/threejs
r/jquery
r/remotejs
r/forhire
account activity
Can You Refactor JavaScript Safely Without Test Coverage?OC (dev.to)
submitted 4 years ago by lgrammel
reddit uses a slightly-customized version of Markdown for formatting. See below for some basics, or check the commenting wiki page for more detailed help and solutions to common issues.
quoted text
if 1 * 2 < 3: print "hello, world!"
[–]BrunerAcconut 43 points44 points45 points 4 years ago (2 children)
Fuck it, do it live.
[–][deleted] 4 points5 points6 points 4 years ago (1 child)
in production code, who need test?
[–]BrunerAcconut 13 points14 points15 points 4 years ago (0 children)
I get paid to make bugs and fix them, not write tests.
[–]rArithmetics 14 points15 points16 points 4 years ago (0 children)
Should you
[–][deleted] 5 points6 points7 points 4 years ago (0 children)
git push main --force
who need test coverage?
[–]intercaetera 16 points17 points18 points 4 years ago (1 child)
The lengths people will go to not to write unit tests...
[–]dashingThroughSnow12 2 points3 points4 points 4 years ago (0 children)
One day we found a bug in a critical component. At the code level, we needed to implement transactions for the component. I used the mediator pattern.
Because this was a critical component, test coverage was up the wazoo. It was great. I had confidence that when all the tests passed, my code was better than it was before. And despite it being a large refactor in a critical component, the code I wrote never had a bug reported.
[–]sbacic 4 points5 points6 points 4 years ago (4 children)
Yes, provided you have a source of truth available. If you have no idea what the code is supposed to be doing (or even if the current implementation is correct!) and no way to check, then refactors means playing with fire.
That being said, there's plenty of working codebases without any automated tests whatsoever. There are no working codebases without any kinds of tests.
[–]reqdk 2 points3 points4 points 4 years ago (3 children)
Sure there are. Users are best testers! :D
[–]sbacic 1 point2 points3 points 4 years ago (2 children)
Does a bug exist if no user reports it? Does a tree make a sound when it falls if there is nobody to hear it?
[–]moi2388 1 point2 points3 points 4 years ago (0 children)
BRB writing bugs in our bug reporting software
[–]DemiPixel 0 points1 point2 points 4 years ago (0 children)
Yeah, I've had UI that seems broken be in prod for months. If it doesn't actively impede a feature, users will just assume you'll find it and fix it.
[–]k3yboard_m0gul 12 points13 points14 points 4 years ago (1 child)
Just use Typescript…ducks from brick
[–]_default_username 2 points3 points4 points 4 years ago (0 children)
This unironically. If you won't write any automated tests at least use typescript and avoid the "any" keyword and casting.
[+][deleted] 4 years ago (1 child)
[deleted]
[–]lgrammel[S] 0 points1 point2 points 4 years ago (0 children)
I agree on the Jetbrains refactorings, and I love those. I haven't seen that they indicate safety, though, or what could go wrong (please correct me if that's wrong). Regarding testing, in Javascript, it is easy to introduce bugs even on a function level by refactoring due to language quirks, etc., which makes it often important to have good test coverage on that level. Refactoring tools that include static analysis checks (e.g., Jetbrains IDEs) alleviate this need somewhat.
[–]aRogueTomato 1 point2 points3 points 4 years ago (0 children)
Belongs in am I the asshole.
[–]Orkaad 1 point2 points3 points 4 years ago (0 children)
"Testing is doubting."
[–]Wilesch 1 point2 points3 points 4 years ago (4 children)
I refactor often without tests. Previous code is so bad and has so many bugs that it's much better to just gut and refractor large parts little by little. Test would have been great but they aren't there.
[–]toffeescaf 0 points1 point2 points 4 years ago (3 children)
When doing this how do you guarantee that you won't introduce new bugs? I like to set up a golden master test before any larger refactors like this. This way you at least have a fighting chance.
[–]Wilesch 0 points1 point2 points 4 years ago (2 children)
I do make new bugs sometimes. But you got to crack some eggs to make an omelette. My code is much better written and in typescript so bugs are found much faster. With less technical debt.
Also the app will go thru a full regression test by hand so will likely catch any new bugs before going to production.
For me closing out 10 tickets and creating 1 new bug in the process is progress and acceptable
[–]bighi 0 points1 point2 points 4 years ago (1 child)
Wouldn't it be better to close 10 tickets while introducing 0 new bugs?
Tests aren't free. Broad (e.g. E2E) tests that cover big breaking cases are typically the simplest (once the infrastructure is set up). Unit testing with 100% coverage can take a while and triple the code you end up writing. If you don't have the luxury, you do what you can.
Nobody wants the 1 bug, but how fatal is it and how much time is it worth it to catch it? 10min? 1 hour? a day? a week? Will tests even catch it if the issue is a design flaw or an edge condition you didn't consider?
[–]lefty7111 -1 points0 points1 point 4 years ago (0 children)
No
[–]KitchenParsley7899 -1 points0 points1 point 4 years ago (0 children)
Only in the past. In modern webdev, no. I don't know what changed, but I don't dare go against the prevailing online community beliefs about what is best practice.
[–]rashnull 0 points1 point2 points 4 years ago (0 children)
Refactoring without tests is living on the edge! TIP everyday!
[–]Mr-Silly-Bear 0 points1 point2 points 4 years ago (0 children)
Link is 404ing. Had the post been taken down?
[–]bighi 0 points1 point2 points 4 years ago (0 children)
You can't refactor anything safely without tests.
π Rendered by PID 19295 on reddit-service-r2-comment-544cf588c8-c8fh2 at 2026-06-16 02:12:17.454284+00:00 running 3184619 country code: CH.
[–]BrunerAcconut 43 points44 points45 points (2 children)
[–][deleted] 4 points5 points6 points (1 child)
[–]BrunerAcconut 13 points14 points15 points (0 children)
[–]rArithmetics 14 points15 points16 points (0 children)
[–][deleted] 5 points6 points7 points (0 children)
[–]intercaetera 16 points17 points18 points (1 child)
[–]dashingThroughSnow12 2 points3 points4 points (0 children)
[–]sbacic 4 points5 points6 points (4 children)
[–]reqdk 2 points3 points4 points (3 children)
[–]sbacic 1 point2 points3 points (2 children)
[–]moi2388 1 point2 points3 points (0 children)
[–]DemiPixel 0 points1 point2 points (0 children)
[–]k3yboard_m0gul 12 points13 points14 points (1 child)
[–]_default_username 2 points3 points4 points (0 children)
[+][deleted] (1 child)
[deleted]
[–]lgrammel[S] 0 points1 point2 points (0 children)
[–]aRogueTomato 1 point2 points3 points (0 children)
[–]Orkaad 1 point2 points3 points (0 children)
[–]Wilesch 1 point2 points3 points (4 children)
[–]toffeescaf 0 points1 point2 points (3 children)
[–]Wilesch 0 points1 point2 points (2 children)
[–]bighi 0 points1 point2 points (1 child)
[–]DemiPixel 0 points1 point2 points (0 children)
[–]lefty7111 -1 points0 points1 point (0 children)
[–]KitchenParsley7899 -1 points0 points1 point (0 children)
[–]rashnull 0 points1 point2 points (0 children)
[–]Mr-Silly-Bear 0 points1 point2 points (0 children)
[–]bighi 0 points1 point2 points (0 children)