Options
All
  • Public
  • Public/Protected
  • All
Menu

Class Mocha

Hierarchy

Index

Type aliases

Static AsyncFunc

AsyncFunc: function

Async callback function used for tests and hooks.

Type declaration

Static Done

Done: function

Type declaration

    • (err?: any): void
    • Parameters

      • Optional err: any

      Returns void

Static Func

Func: function

Callback function used for tests and hooks.

Type declaration

Static IStats

IStats: Stats
deprecated

use Mocha.Stats instead.

Static Interface

Interface: keyof InterfaceContributions

Static Reporter

Reporter: keyof ReporterContributions

Static TestInterface

TestInterface: function

Type declaration

    • Parameters

      Returns void

Constructors

constructor

  • Parameters

    Returns Mocha

Properties

files

files: string[]

options

suite

suite: Suite

Static after

Execute after running tests.

  • Only available when invoked via the mocha CLI.
see

https://mochajs.org/api/global.html#after

Static afterEach

afterEach: HookFunction

Execute after each test case.

  • Only available when invoked via the mocha CLI.
see

https://mochajs.org/api/global.html#afterEach

Static before

before: HookFunction

Execute before running tests.

  • Only available when invoked via the mocha CLI.
see

https://mochajs.org/api/global.html#before

Static beforeEach

beforeEach: HookFunction

Execute before each test case.

  • Only available when invoked via the mocha CLI.
see

https://mochajs.org/api/global.html#beforeEach

Static describe

describe: SuiteFunction

Describe a "suite" containing nested suites and tests.

  • Only available when invoked via the mocha CLI.

Static it

Describes a test case.

  • Only available when invoked via the mocha CLI.

Static setup

Execute before each test case.

  • Only available when invoked via the mocha CLI.
see

https://mochajs.org/api/global.html#beforeEach

Static suite

Describe a "suite" containing nested suites and tests.

  • Only available when invoked via the mocha CLI.

Static suiteSetup

suiteSetup: HookFunction

Execute before running tests.

  • Only available when invoked via the mocha CLI.
see

https://mochajs.org/api/global.html#before

Static suiteTeardown

suiteTeardown: HookFunction

Execute after running tests.

  • Only available when invoked via the mocha CLI.
see

https://mochajs.org/api/global.html#after

Static teardown

teardown: HookFunction

Execute after each test case.

  • Only available when invoked via the mocha CLI.
see

https://mochajs.org/api/global.html#afterEach

Static test

Describes a test case.

  • Only available when invoked via the mocha CLI.

Static xit

Describes a pending test case.

  • Only available when invoked via the mocha CLI.

Methods

addFile

  • addFile(file: string): this

allowUncaught

  • allowUncaught(): boolean

asyncOnly

  • asyncOnly(): this

bail

  • bail(bail?: undefined | false | true): this
  • Enable or disable bailing on the first failure.

    see

    https://mochajs.org/api/mocha#bail

    Parameters

    • Optional bail: undefined | false | true

    Returns this

checkLeaks

  • checkLeaks(): this

delay

  • delay(): boolean

enableTimeouts

  • enableTimeouts(enabled?: undefined | false | true): this

fgrep

  • fgrep(str: string): this

forbidOnly

  • forbidOnly(): boolean

forbidPending

  • forbidPending(): boolean

fullTrace

  • fullTrace(): this

globals

  • globals(globals: string | ReadonlyArray<string>): this
  • Ignore globals array or string.

    see

    https://mochajs.org/api/mocha#globals

    Parameters

    • globals: string | ReadonlyArray<string>

    Returns this

grep

  • grep(re: string | RegExp): this
  • Add regexp to grep, if re is a string it is escaped.

    see

    https://mochajs.org/api/mocha#grep

    Parameters

    • re: string | RegExp

    Returns this

growl

  • growl(): this

hideDiff

  • hideDiff(hideDiff: boolean): this

ignoreLeaks

  • ignoreLeaks(ignore: boolean): this

invert

  • invert(): this

Protected loadFiles

  • loadFiles(fn?: undefined | function): void

noHighlighting

  • noHighlighting(): this

reporter

  • reporter(reporter: Reporter, reporterOptions?: any): this
  • reporter(reporter?: string | ReporterConstructor, reporterOptions?: any): this
  • Set reporter to one of the built-in reporters.

    see

    https://mochajs.org/api/mocha#reporter

    Parameters

    • reporter: Reporter
    • Optional reporterOptions: any

    Returns this

  • Set reporter to the provided constructor, one of the built-in reporters, or loads a reporter from a module path. Defaults to "spec".

    see

    https://mochajs.org/api/mocha#reporter

    Parameters

    Returns this

retries

  • retries(n: number): this

run

  • run(fn?: undefined | function): Runner
  • Run tests and invoke fn() when complete.

    Note that run 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.

    see

    https://mochajs.org/api/mocha#run

    Parameters

    • Optional fn: undefined | function

    Returns Runner

slow

  • slow(slow: string | number): this
  • Set slowness threshold in milliseconds.

    see

    https://mochajs.org/api/mocha#slow

    Parameters

    • slow: string | number

    Returns this

timeout

  • timeout(timeout: string | number): this

ui

  • ui(name: Interface): this
  • ui(name?: undefined | string): this
  • Set test UI to one of the built-in test interfaces.

    see

    https://mochajs.org/api/mocha#ui

    Parameters

    Returns this

  • Set test UI to one of the built-in test interfaces or loads a test interface from a module path. Defaults to "bdd".

    see

    https://mochajs.org/api/mocha#ui

    Parameters

    • Optional name: undefined | string

    Returns this

useColors

  • useColors(colors: boolean): this

useInlineDiffs

  • useInlineDiffs(inlineDiffs: boolean): this

Static run

  • run(): void
  • Triggers root suite execution.

    • Only available if flag --delay is passed into Mocha.
    • Only available when invoked via the mocha CLI.
    see

    https://mochajs.org/api/global.html#runWithSuite

    Returns void

Generated using TypeDoc