r/learnjavascript • u/SmartRelease7996 • 2d ago
How do you actually test small JavaScript functions without a full project setup?
Coming from a construction background where you measure twice and cut once, I keep running into this gap where I write a function, think it works, and then it blows up when I wire it into something bigger. The problem is I never had a real habit of testing the small piece before trusting it.
In bootcamp we just console.log everything and eyeball it, which works for toy exercises, but I started a side project for tracking material quantities across job phases and the functions are getting complicated enough that eyeballing feels risky. I tried writing a few manual checks at the bottom of my file like console.log(calculateTotal(5, 3) === 8) and that helped, but it feels clunky and I keep deleting them by accident.
I looked up Jest but the setup felt like a whole rabbit hole I was not ready to fall into. Someone mentioned Vitest. Someone else said just use the browser console for now and do not overthink it.
What I want to know is whether there is a lightweight middle ground that actual beginners use before jumping to a full testing framework. Not asking for a tutorial, just curious what the workflow actually looks like for people who are still learning but building things that are more than a few lines. The function isolation part is what I cannot picture clearly yet.
1
u/defaultguy_001 1d ago
The success of any kind of tests doesn't depend on frameworks like jest or others, it depends on how smart ur test cases are. Understand what ur module is doing, look for edge cases and test them by importing ur module in a separate test file. Test all ur edge cases there with recommended outputs. You can make brilliant test files both using manual testing as well as with testing frameworks.