Search⌘ K
AI Features

Use Jasmine to Run Unit Tests

Explore how to use Jasmine to run unit tests in JavaScript by understanding spec file patterns, describe and it containers, and test execution results to ensure accurate code testing.

We'll cover the following...

Jasmine

Jasmine is a framework for testing code in JavaScript. It’s a tool that:

  • finds all test files (also known as specification, or spec, files).
  • runs the tests.
  • reports on the result: ok, fail, and skip.

Jasmine allows us to avoid the inconvenience of having our code and its tests in the same file. The test code isn’t beneficial to users, and we don’t want our users to see the console logs of our tests.

Run the code below to see an example of what Jasmine outputs.

{
  "spec_dir": "src",
  "spec_files": [
    "**/*[sS]pec.js"
  ],
  "stopSpecOnExpectationFailure": false,
  "random": false
}
Example of a couple of specs

Breakdown

The jasmine.json file in the spec/support folder configures Jasmine.

The src is the ...