Run tests with default configuration or as configured in mocha.opts

$ mocha

Run tests contained at a specific location
$ mocha [directory/with/tests]

Run tests that match a specific grep pattern
$ mocha --grep [regular_expression]

Run tests on changes to JavaScript files in the current directory and once initially
$ mocha --watch

Run tests with a specific reporter
$ mocha --reporter [reporter]


mocha [spec..]

Run tests with Mocha


mocha inspect [spec..]

Run tests with Mocha [default]

mocha init <path>

create a client-side Mocha setup at <path>

Rules & Behavior


Allow uncaught errors to propagate [boolean]

--async-only, -A

Require all tests to use a callback (async) or return a Promise [boolean]

--bail, -b

Abort ("bail") after first test failure [boolean]


Check for global variable leaks [boolean]


Delay initial execution of root suite [boolean]


Force Mocha to quit after tests complete [boolean]


Fail if exclusive test(s) encountered [boolean]


Fail if pending test(s) encountered [boolean]

--global, --globals

List of allowed global variables [array]

--jobs, -j

Number of concurrent jobs for --parallel; use 1 to run in serial

[number] [default: (number of CPU cores - 1)]

--parallel, -p

Run tests in parallel [boolean]


Retry failed tests this many times [number]

--slow, -s

Specify "slow" test threshold (in milliseconds) [string] [default: 75]

--timeout, -t, --timeouts

Specify test timeout threshold (in milliseconds) [string] [default: 2000]

--ui, -u

Specify user interface [string] [default: "bdd"]

Reporting & Output

--color, -c, --colors

Force-enable color output [boolean]


Show diff on failure [boolean] [default: true]


Display full stack traces [boolean]

--growl, -G

Enable Growl notifications [boolean]


Display actual/expected differences inline within each string [boolean]

--reporter, -R

Specify reporter to use [string] [default: "spec"]

--reporter-option, --reporter-options,

Reporter-specific options


(<k=v,[k1=v1,..]>) [array]



Path to config file [string] [default: (nearest rc file)]


Path to package.json for config [string]

File Handling


File extension(s) to load [array] [default: ["js","cjs","mjs"]]


Specify file(s) to be loaded prior to root suite execution [array] [default: (none)]

--ignore, --exclude

Ignore file(s) or glob pattern(s) [array] [default: (none)]


Look for tests in subdirectories [boolean]

--require, -r

Require module [array] [default: (none)]

--sort, -S

Sort test files [boolean]

--watch, -w

Watch files in the current working directory for changes [boolean]


List of paths or globs to watch [array]


List of paths or globs to exclude from watching [array] [default: ["node_modules",".git"]]

Test Filters

--fgrep, -f

Only run tests containing this string [string]

--grep, -g

Only run tests matching this string or regexp [string]

--invert, -i

Inverts --grep and --fgrep matches [boolean]

Positional Arguments


One or more files, directories, or globs to test

[array] [default: ["test"]]


--help, -h

Show usage information & exit [boolean]

--version, -V

Show version number & exit [boolean]


List built-in user interfaces & exit [boolean]


List built-in reporters & exit [boolean]

Mocha Resources




Copied to clipboard