Mocha.js: Running in the Browser Cheat Sheet

Every release of Mocha will have new builds of ./mocha.js and ./mocha.css for use in the browser.

Browser-specific methods

The following method(s) only function in a browser context:

mocha.allowUncaught() : If called, uncaught errors will not be absorbed by the error handler.

A typical setup might look something like the following, where we call mocha.setup('bdd') to use the BDD interface before loading the test scripts, running them onload with

  <meta charset="utf-8">
  <title>Mocha Tests</title>
  <link href="[email protected]/mocha.css" rel="stylesheet" />
  <div id="mocha"></div>

  <script src=""></script>
  <script src="[email protected]/mocha.js"></script>

  <script src="test.array.js"></script>
  <script src="test.object.js"></script>
  <script src="test.xhr.js"></script>


The browser may use the --grep as functionality. Append a query-string to your URL: ?grep=api.

Browser Configuration

Mocha options can be set via mocha.setup()

Leave a Reply

Your email address will not be published.