Mocha API

see

  https://mochajs.org/api/mocha

### Hierarchy

- Mocha
  - BrowserMocha

## Index

### Modules

- interfaces
- reporters
- utils

### Classes

- Context
- Hook
- Runnable
- Runner
- Suite
- Test

### Interfaces

- ExclusiveSuiteFunction
- ExclusiveTestFunction
- HookFunction
- IBeforeAndAfterContext
- IContext
- IContextDefinition
- IHook
- IHookCallbackContext
- IRunnable
- IRunner
- ISuite
- ISuiteCallbackContext
- ITest
- ITestCallbackContext
- ITestDefinition
- InterfaceContributions
- MochaGlobals
- MochaInstanceOptions
- MochaOptions
- PendingSuiteFunction
- PendingTestFunction
- ReporterConstructor
- ReporterContributions
- Stats
- SuiteFunction
- TestFunction

### Type aliases

- AsyncFunc
- Done
- Func
- IStats
- Interface
- Reporter
- TestInterface

### Constructors

- constructor

### Properties

- _growl
- _reporter
- _ui
- files
- options
- suite
- after
- afterEach
- before
- beforeEach
- describe
- it
- setup
- suite
- suiteSetup
- suiteTeardown
- teardown
- test
- xit

### Methods

- addFile
- allowUncaught
- asyncOnly
- bail
- checkLeaks
- delay
- enableTimeouts
- fgrep
- forbidOnly
- forbidPending
- fullTrace
- globals
- grep
- growl
- hideDiff
- ignoreLeaks
- invert
- loadFiles
- noHighlighting
- reporter
- retries
- run
- slow
- timeout
- ui
- useColors
- useInlineDiffs
- run

## Type aliases

### Static AsyncFunc

AsyncFunc: function

- Defined in node_modules/@types/mocha/index.d.ts:2177

Async callback function used for tests and hooks.

#### Type declaration

- - (this: Context): PromiseLike<any>

  - #### Parameters

    - ##### this: Context

    #### Returns PromiseLike<any>

### Static Done

Done: function

- Defined in node_modules/@types/mocha/index.d.ts:2167

#### Type declaration

- - (err?: any): void

  - #### Parameters

    - ##### Optional err: any

    #### Returns void

### Static Func

Func: function

- Defined in node_modules/@types/mocha/index.d.ts:2172

Callback function used for tests and hooks.

#### Type declaration

- - (this: Context, done: Done): void

  - #### Parameters

    - ##### this: Context

    - ##### done: Done

    #### Returns void

### Static IStats

IStats: Stats

- Defined in node_modules/@types/mocha/index.d.ts:2574

deprecated

  use `Mocha.Stats` instead.

### Static Interface

Interface: keyof InterfaceContributions

- Defined in node_modules/@types/mocha/index.d.ts:2442

### Static Reporter

Reporter: keyof ReporterContributions

- Defined in node_modules/@types/mocha/index.d.ts:2429

### Static TestInterface

TestInterface: function

- Defined in node_modules/@types/mocha/index.d.ts:2161

#### Type declaration

- - (suite: Suite): void

  - #### Parameters

    - ##### suite: Suite

    #### Returns void

## Constructors

### constructor

- new Mocha(options?: MochaOptions): Mocha

- - Defined in node_modules/@types/mocha/index.d.ts:20

  #### Parameters

  - ##### Optional options: MochaOptions

  #### Returns Mocha

## Properties

### Private _growl

_growl: any

- Defined in node_modules/@types/mocha/index.d.ts:18

### Private _reporter

_reporter: any

- Defined in node_modules/@types/mocha/index.d.ts:19

### Private _ui

_ui: any

- Defined in node_modules/@types/mocha/index.d.ts:20

### files

files: string[]

- Defined in node_modules/@types/mocha/index.d.ts:25

### options

options: MochaInstanceOptions

- Defined in node_modules/@types/mocha/index.d.ts:26

### suite

suite: Suite

- Defined in node_modules/@types/mocha/index.d.ts:24

### Static after

after: HookFunction

- Defined in node_modules/@types/mocha/index.d.ts:573

Execute after running tests.

- Only available when invoked via the mocha CLI.

see

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

### Static afterEach

afterEach: HookFunction

- Defined in node_modules/@types/mocha/index.d.ts:564

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

- Defined in node_modules/@types/mocha/index.d.ts:591

Execute before running tests.

- Only available when invoked via the mocha CLI.

see

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

### Static beforeEach

beforeEach: HookFunction

- Defined in node_modules/@types/mocha/index.d.ts:582

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

- Defined in node_modules/@types/mocha/index.d.ts:598

Describe a "suite" containing nested suites and tests.

- Only available when invoked via the mocha CLI.

### Static it

it: TestFunction

- Defined in node_modules/@types/mocha/index.d.ts:605

Describes a test case.

- Only available when invoked via the mocha CLI.

### Static setup

setup: HookFunction

- Defined in node_modules/@types/mocha/index.d.ts:621

Execute before each test case.

- Only available when invoked via the mocha CLI.

see

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

### Static suite

suite: SuiteFunction

- Defined in node_modules/@types/mocha/index.d.ts:646

Describe a "suite" containing nested suites and tests.

- Only available when invoked via the mocha CLI.

### Static suiteSetup

suiteSetup: HookFunction

- Defined in node_modules/@types/mocha/index.d.ts:630

Execute before running tests.

- Only available when invoked via the mocha CLI.

see

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

### Static suiteTeardown

suiteTeardown: HookFunction

- Defined in node_modules/@types/mocha/index.d.ts:639

Execute after running tests.

- Only available when invoked via the mocha CLI.

see

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

### Static teardown

teardown: HookFunction

- Defined in node_modules/@types/mocha/index.d.ts:655

Execute after each test case.

- Only available when invoked via the mocha CLI.

see

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

### Static test

test: TestFunction

- Defined in node_modules/@types/mocha/index.d.ts:662

Describes a test case.

- Only available when invoked via the mocha CLI.

### Static xit

xit: PendingTestFunction

- Defined in node_modules/@types/mocha/index.d.ts:612

Describes a pending test case.

- Only available when invoked via the mocha CLI.

## Methods

### addFile

- addFile(file: string): this

- - Defined in node_modules/@types/mocha/index.d.ts:40

  Add test `file`.

  see

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

  #### Parameters

  - ##### file: string

  #### Returns this

### allowUncaught

- allowUncaught(): boolean

- - Defined in node_modules/@types/mocha/index.d.ts:196

  Enable uncaught errors to propagate (in browser).

  see

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

  #### Returns boolean

### asyncOnly

- asyncOnly(): this

- - Defined in node_modules/@types/mocha/index.d.ts:182

  Makes all tests async (accepting a callback)

  see

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

  #### Returns this

### bail

- bail(bail?: undefined | false | true): this

- - Defined in node_modules/@types/mocha/index.d.ts:33

  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

- - Defined in node_modules/@types/mocha/index.d.ts:105

  Enable global leak checking.

  see

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

  #### Returns this

### delay

- delay(): boolean

- - Defined in node_modules/@types/mocha/index.d.ts:203

  Delay root suite execution.

  see

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

  #### Returns boolean

### enableTimeouts

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

- - Defined in node_modules/@types/mocha/index.d.ts:175

  Enable timeouts.

  see

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

  #### Parameters

  - ##### Optional enabled: undefined | false | true

  #### Returns this

### fgrep

- fgrep(str: string): this

- - Defined in node_modules/@types/mocha/index.d.ts:77

  Escape string and add it to grep as a RegExp.

  see

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

  #### Parameters

  - ##### str: string

  #### Returns this

### forbidOnly

- forbidOnly(): boolean

- - Defined in node_modules/@types/mocha/index.d.ts:210

  Tests marked only fail the suite

  see

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

  #### Returns boolean

### forbidPending

- forbidPending(): boolean

- - Defined in node_modules/@types/mocha/index.d.ts:217

  Pending tests and tests marked skip fail the suite

  see

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

  #### Returns boolean

### fullTrace

- fullTrace(): this

- - Defined in node_modules/@types/mocha/index.d.ts:112

  Display long stack-trace on failing

  see

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

  #### Returns this

### globals

- globals(globals: string | ReadonlyArray<string>): this

- - Defined in node_modules/@types/mocha/index.d.ts:126

  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

- - Defined in node_modules/@types/mocha/index.d.ts:84

  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

- - Defined in node_modules/@types/mocha/index.d.ts:119

  Enable growl support.

  see

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

  #### Returns this

### hideDiff

- hideDiff(hideDiff: boolean): this

- - Defined in node_modules/@types/mocha/index.d.ts:147

  Do not show diffs at all.

  see

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

  #### Parameters

  - ##### hideDiff: boolean

  #### Returns this

### ignoreLeaks

- ignoreLeaks(ignore: boolean): this

- - Defined in node_modules/@types/mocha/index.d.ts:98

  Ignore global leaks.

  see

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

  #### Parameters

  - ##### ignore: boolean

  #### Returns this

### invert

- invert(): this

- - Defined in node_modules/@types/mocha/index.d.ts:91

  Invert `.grep()` matches.

  see

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

  #### Returns this

### Protected loadFiles

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

- - Defined in node_modules/@types/mocha/index.d.ts:239

  Load registered files.

  see

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

  #### Parameters

  - ##### Optional fn: undefined | function

  #### Returns void

### noHighlighting

- noHighlighting(): this

- - Defined in node_modules/@types/mocha/index.d.ts:189

  Disable syntax highlighting (in browser).

  see

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

  #### Returns this

### reporter

- reporter(reporter: Reporter, reporterOptions?: any): this
- reporter(reporter?: string | ReporterConstructor, reporterOptions?: any): this

- - Defined in node_modules/@types/mocha/index.d.ts:47

  Set reporter to one of the built-in reporters.

  see

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

  #### Parameters

  - ##### reporter: Reporter

  - ##### Optional reporterOptions: any

  #### Returns this

- - Defined in node_modules/@types/mocha/index.d.ts:55

  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

  - ##### Optional reporter: string | ReporterConstructor

  - ##### Optional reporterOptions: any

  #### Returns this

### retries

- retries(n: number): this

- - Defined in node_modules/@types/mocha/index.d.ts:161

  Set the number of times to retry failed tests.

  see

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

  #### Parameters

  - ##### n: number

  #### Returns this

### run

- run(fn?: undefined | function): Runner

- - Defined in node_modules/@types/mocha/index.d.ts:232

  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

- - Defined in node_modules/@types/mocha/index.d.ts:168

  Set slowness threshold in milliseconds.

  see

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

  #### Parameters

  - ##### slow: string | number

  #### Returns this

### timeout

- timeout(timeout: string | number): this

- - Defined in node_modules/@types/mocha/index.d.ts:154

  Set the timeout in milliseconds.

  see

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

  #### Parameters

  - ##### timeout: string | number

  #### Returns this

### ui

- ui(name: Interface): this
- ui(name?: undefined | string): this

- - Defined in node_modules/@types/mocha/index.d.ts:62

  Set test UI to one of the built-in test interfaces.

  see

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

  #### Parameters

  - ##### name: Interface

  #### Returns this

- - Defined in node_modules/@types/mocha/index.d.ts:70

  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

- - Defined in node_modules/@types/mocha/index.d.ts:133

  Emit color output.

  see

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

  #### Parameters

  - ##### colors: boolean

  #### Returns this

### useInlineDiffs

- useInlineDiffs(inlineDiffs: boolean): this

- - Defined in node_modules/@types/mocha/index.d.ts:140

  Use inline diffs rather than +/-.

  see

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

  #### Parameters

  - ##### inlineDiffs: boolean

  #### Returns this

### Static run

- run(): void

- - Defined in node_modules/@types/mocha/index.d.ts:672

  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