4 ways to unit test JS in Codepen

Datetime:2016-08-23 02:49:29         Topic: JavaScript  Unit Testing          Share        Original >>
Here to See The Original Article!!!

A quick search through CodePen shows that many have figured out how to unit test JS in a pen already. Here are four pens I forked to show you how to set up JS unit tests with Mocha/Chai, Jasmine, Tape and qUnit.

  • Feel free to hack your own functions and tests in. All the code is editable from this page in these pens.
  • All pens test this simple adding function const addr = (a, b) => a + b; .
  • All tests have a "failing" test that is commented out. Remove the comment if you want to see what a failing test looks like.

Mocha and Chai

Forked fromSitepoint


Forked fromBrian Holt


Forked fromHussein Morsy


Forked fromAndrew Worcester


The first challenge with unit testing is figuring out how to do it in the first place. The second challenge is just making yourself do it. The third challenge is keeping your tests simple. Regardless, if you need to set up a quick test in a pen, then fork one of these and get to testing.

Wanna read up on unit testing?

Here you go:

Go fall in love. Stay awesome!


Put your ads here, just $200 per month.