JavaScript Unit-Testing using Karma Module

Learn how to set up a JavaScript unit-test using Karma, a karma.conf.js file, managing Karma, configuring Karma, and manifest files.

Karma

Karma is easiest to run if we install the karma-cli module, but since that’s external to this project, it’s best to install it as a global module so that the karma command is just available.

$ yarn global add karma-cli

Configuring Karma

Now that all the modules are loaded, some configuration is necessary. Let’s start with Karma. All kinds of details that RSpec and Rails handle for us under the banner of “convention over configuration” are actually configuration options in Karma, and the file goes in karma.conf.js. We can get Karma to generate a starting configuration file with the command karma init, but we won’t walk through that here. We’ll just show the finished product.

Here’s the file:

Get hands-on with 1400+ tech skills courses.