How do you test your Javascript code?

Hi,

For the javascript algorithms and data structures projects I wrote the code in VS Code editor, used Node.JS to execute it from the command line and needed a lot of console.log statements to debug my code.

There must be an easier way to test and debug your code. How do you test your code?
A Google search gave me the following results for “javascript testing framework”:

  • MochaJS

  • Jest

  • Jasmine

  • Karma

  • Puppeteer

Any recommendations? I asked the question on Twitter, but apparently I do not have enough clout to get an answer.

Cheers

Hi Johmar
correct I use jamine & mocha, but they all go very well knowing how to use them here I leave the link of jasmine read the documentation or search on youtube. I hope it helps you
https://jasmine.github.io/

1 Like
1 Like

Hey @johmar, I’m no expert by any means but Karma and Puppeteer serve a different purpose than the previous 3 you’ve listed.

Karma is more of a task runner for tests, while Puppeteer spawns a headless chrome browser.

So for starter I suggest to stick with one of the first 3 you’ve listed, they are all valid and loved.

However, my personal preference goes to Jest, to me it’s by far the easier to start with, works with zero to almost none configuration and doesn’t require any additional plugin.

But again, you cannot go wrong with any on them :slight_smile:

1 Like

Two different things here: testing and debugging.

For debugging I use breakpoints and occasionally some console statements (mostly to break up my code in a way that makes it easier to use breakpoints).

Tests are used to ensure code quality. They make sure that requirements are being met (like the test suite used by freeCodeCamp for the projects) and they make sure that the functionality is not broken by future changes. This is where your search results come in.

1 Like