John Aaron Nelson

My Favorite JavaScript Unit Testing Resources

August 10, 2016

As part of the CodeScience Delivery Team, we are faced with developing products for the AppExchange in record speed. Faster than fast. Cheetah with a jetpack fast. So you can imagine that we are always in the lookout for tools and resources that can help us deliver the goods for our clients. Here is a quick list of my favorite tools to help you accelerate your JavaScript Unit Testing.

Wallaby

Wallaby is an incredible tool. "wallaby.js runs your code as you write it." It can be used with a variety of editors, namely Sublime Text, Atom, Visual Studio Code, Visual Studio Standard, and IntelliJ. The great thing about Wallaby is that it puts line pass/fail markers in the gutter of your editor and runs your tests on every keystroke. It's kind of hard to describe. But if you see it, you may understand. It is transformational. Every keystroke, your code runs, and you're alerted if it's valid or not, and if not, what the error is.  No more questions of "will this code run?" You know, every keystroke, if what you wrote will run or not.  

Mocha

Mocha - "The simple, flexible, and fun testing framework."  This tool is mainly used as the test runner. It has a great set of defaults, which means the no config OOTB is pretty great. It has a debug version, _mocha, which allows you to debug your tests. With Visual Studio Code you can write and debug your tests with breakpoints in the IDE.

Chai

Chai - "Chai is a BDD / TDD assertion library for node and the browser that can be delightfully paired with any javascript testing framework." Chai pairs wonderfully with Mocha and has a great BDD assertion style that is very flexible and expressive work chains. It also has a chai-as-promised extension that allows for assertions to be done as part of a promise chain. For those of us who love Promises, it's a great thing.

Webdriver.io

Webdriver.io provides Selenium bindings for Node.js - in other words, you can drive a web browser with JavaScript. It's pretty cool.  

Intern / Chimp

Intern / Chimp are two testing meta-frameworks. What is a meta-framework you ask? Testing meta-frameworks are tools that combine other tools and testing frameworks into a more coherent and cohesive package. If you aren't very well experienced with testing tools, these all-in-one meta-frameworks help you get Selenium, PhantomJS, Mocha, etc... setup easily. Chimp is my personal favorite. The guy who runs it is fantastic.  

Cucumber.js

Cucumber.js is Cucumber for JavaScript. Cucumber is a technology that uses Gherkin to express tests in natural language, most often used in Behavior Driven Development methodologies. 

Lastly, all of these tools work great with Visual Studio Code and Visual Studio Code works great with Salesforce via ForceCode

What do you use for unit testing?


John Nelson

Written by John Nelson, who lives and works in Chattanooga, building things for Batch.sh.