Mocha

Mocha

new Mocha(options)

Source:

Set up mocha with options.

Options:

  • ui name "bdd", "tdd", "exports" etc
  • reporter reporter instance, defaults to mocha.reporters.spec
  • globals array of accepted globals
  • timeout timeout in milliseconds
  • retries number of times to retry failed tests
  • bail bail on the first test failure
  • slow milliseconds to wait before considering a test slow
  • ignoreLeaks ignore global leaks
  • fullTrace display the full stack-trace on failing
  • grep string or regexp to filter tests with
Parameters:
NameTypeDescription
optionsObject

Classes

Runner
Suite
utils

Members

(static) exports.reporters

Source:

(static) exports.Runner

Source:

Methods

(static) exports.create(parent, title) → {Suite}

Source:

Create a new Suite with the given title and parent Suite. When a suite
with the same title is already present, that suite is returned to provide
nicer reporter and more flexible meta-testing.

Parameters:
NameTypeDescription
parentSuite
titlestring
Returns:
Type
Suite

(static) module.exports(val) → {string|number}

Source:

Parse or format the given val.

Parameters:
NameTypeDescription
valstring | number
Returns:
Type
string | number

_growl()

Source:

Enable growl support.

addFile(file)

Source:

Add test file.

Parameters:
NameTypeDescription
filestring

allowUncaught() → {Mocha}

Source:

Enable uncaught errors to propagate (in browser).

Returns:
Type
Mocha

asyncOnly() → {Mocha}

Source:

Makes all tests async (accepting a callback)

Returns:
Type
Mocha

bail(bailopt)

Source:

Enable or disable bailing on the first failure.

Parameters:
NameTypeAttributesDescription
bailboolean<optional>

checkLeaks() → {Mocha}

Source:

Enable global leak checking.

Returns:
Type
Mocha

delay() → {Mocha}

Source:

Delay root suite execution.

Returns:
Type
Mocha

enableTimeouts(enabled, enabled) → {Mocha|Mocha}

Source:

Enable timeouts.

Parameters:
NameTypeDescription
enabledBoolean
enabledboolean
Returns:

fgrep(str) → {Mocha}

Source:

Escape string and add it to grep as a regexp.

Parameters:
NameTypeDescription
str
Returns:
Type
Mocha

forbidOnly() → {Mocha}

Source:

Tests marked only fail the suite

Returns:
Type
Mocha

forbidPending() → {Mocha}

Source:

Pending tests and tests marked skip fail the suite

Returns:
Type
Mocha

fullTrace() → {Mocha}

Source:

Display long stack-trace on failing

Returns:
Type
Mocha

globals(globals, globals) → {Mocha|Mocha}

Source:

Ignore globals array or string.

Parameters:
NameTypeDescription
globalsArray | String
globalsArray | string
Returns:

grep(re, re) → {Mocha|Mocha}

Source:

Add regexp to grep, if re is a string it is escaped.

Parameters:
NameTypeDescription
reRegExp | String
reRegExp | string
Returns:

growl() → {Mocha}

Source:

Enable growl support.

Returns:
Type
Mocha

hideDiff(hideDiff, hideDiff) → {Mocha|Mocha}

Source:

Do not show diffs at all.

Parameters:
NameTypeDescription
hideDiffBoolean
hideDiffboolean
Returns:

ignoreLeaks(ignore, ignore) → {Mocha|Mocha}

Source:

Ignore global leaks.

Parameters:
NameTypeDescription
ignoreBoolean
ignoreboolean
Returns:

invert() → {Mocha}

Source:

Invert .grep() matches.

Returns:
Type
Mocha

loadFiles()

Source:

Load registered files.

noHighlighting()

Source:

Disable syntax highlighting (in browser).

reporter(reporter, reporterOptions, reporter, reporterOptions)

Source:

Set reporter to reporter, defaults to "spec".

Parameters:
NameTypeDescription
reporterString | function

name or constructor

reporterOptionsObject

optional options

reporterstring | function

name or constructor

reporterOptionsObject

optional options

retries(retry) → {Mocha}

Source:

Set the number of times to retry failed tests.

Parameters:
NameTypeDescription
retryNumber

times

Returns:
Type
Mocha

run(fn) → {Runner}

Source:

Run tests and invoke fn() when complete.

Note that loadFiles relies on Node's require to execute
the test interface functions and will be subject to the
cache - if the files are already in the require cache,
they will effectively be skipped. Therefore, to run tests
multiple times or to run tests in files that are already
in the require cache, make sure to clear them from the
cache first in whichever manner best suits your needs.

Parameters:
NameTypeDescription
fnfunction
Returns:
Type
Runner

slow(slow, slow) → {Mocha|Mocha}

Source:

Set slowness threshold in milliseconds.

Parameters:
NameTypeDescription
slowNumber
slownumber
Returns:

timeout(timeout, timeout) → {Mocha|Mocha}

Source:

Set the timeout in milliseconds.

Parameters:
NameTypeDescription
timeoutNumber
timeoutnumber
Returns:

ui(bdd)

Source:

Set test UI name, defaults to "bdd".

Parameters:
NameTypeDescription
bddstring

useColors(colors, colors) → {Mocha|Mocha}

Source:

Emit color output.

Parameters:
NameTypeDescription
colorsBoolean
colorsboolean
Returns:

useInlineDiffs(inlineDiffs, inlineDiffs) → {Mocha|Mocha}

Source:

Use inline diffs rather than +/-.

Parameters:
NameTypeDescription
inlineDiffsBoolean
inlineDiffsboolean
Returns: