Browsers
Mocha runs in the browser.
Every release of Mocha will have new builds of ./mocha.js
and ./mocha.css
for use in the browser.
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 mocha.run()
.
Grep
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()
.
Examples:
Browser-Specific Options
Browser Mocha supports many, but not all CLI options.
To use a CLI option that contains a ”-”, please convert the option to camelCase, (eg. check-leaks
to checkLeaks
).
Options That Differ Slightly From CLI Options
reporter
string|constructor
You can pass a reporter’s name or a custom reporter’s constructor. You can find recommended reporters for the browser here.
It is possible to use built-in reporters as well. Their employment in browsers is neither recommended nor supported, open the console to see the test results.
Options That Only Function In Browser Context
noHighlighting
boolean
If set to true
, do not attempt to use syntax highlighting on output test code.
Reporting
The HTML reporter is the default reporter when running Mocha in the browser. It looks like this:
Mochawesome is a great alternative to the default HTML reporter.