table of contents
| MOCHA(1) | User Commands | MOCHA(1) |
NAME¶
mocha - simple, flexible, fun test framework
SYNOPSIS¶
mocha [spec..]
DESCRIPTION¶
- mocha init <path>
Commands:¶
- init <path>
- create a client-side Mocha setup at <path>
OPTIONS¶
- --extension
- File extension(s) to load
- --file
- Specify file(s) to be loaded prior to root suite execution
- --global, --globals
- List of allowed global variables
- --ignore, --exclude
- Ignore file(s) or glob pattern(s)
- --node-option, -n
- Node or V8 option (no leading "--")
--reporter-option, --reporter-options, -O Reporter-specific options (<k=v,[k1=v1,..]>)
- --require, -r
- Require module
- --watch-files
- List of paths or globs to watch
- --watch-ignore
- List of paths or globs to exclude from watching
- --allow-uncaught
- Allow uncaught errors to propagate
- --async-only, -A
- Require all tests to use a callback (async) or return a Promise
- --bail, -b
- Abort ("bail") after first test failure
- --check-leaks
- Check for global variable leaks
- --color, -c, --colors
- Force-enable color output
- --delay
- Delay initial execution of root suite
- --diff
- Show diff on failure
- --dry-run
- Report tests without executing them
- --exit
- Force Mocha to quit after tests complete
- --fail-hook-affected-tests
- Report tests as failed when affected by hook failures (before/beforeEach)
- --pass-on-failing-test-suite
- Not fail test run if tests were failed
- --fail-zero
- Fail test run if no test(s) encountered
- --forbid-only
- Fail if exclusive test(s) encountered
- --forbid-pending
- Fail if pending test(s) encountered
- --full-trace
- Display full stack traces
- --inline-diffs
- Display actual/expected differences inline within each string
- --invert, -i
- Inverts --grep and --fgrep matches
- --list-interfaces
- List built-in user interfaces & exit
- --list-reporters
- List built-in reporters & exit
- --no-colors, -C
- Force-disable color output
- --parallel, -p
- Run tests in parallel
- --posix-exit-codes
- Use POSIX and UNIX shell exit codes as Mocha's return value
- --recursive
- Look for tests in subdirectories
- --sort, -S
- Sort test files
- --watch, -w
- Watch files in the current working directory for changes
- --retries
- Retry failed tests this many times
- --jobs, -j
- Number of concurrent jobs for --parallel; use 1 to run in serial
- --config
- Path to config file
- --fgrep, -f
- Only run tests containing this string
- --grep, -g
- Only run tests matching this string or regexp
- --package
- Path to package.json for config
- --reporter, -R
- Specify reporter to use
- --ui, -u
- Specify user interface
- --slow, -s
- Specify "slow" test threshold (in milliseconds)
- --timeout, -t, --timeouts
- Specify test timeout threshold (in milliseconds)
- --help, -h
- Show usage information & exit
- --version, -V
- Show version number & exit
Mocha Resources
- Chat: https://discord.gg/KeDn2uXhER
- GitHub: https://github.com/mochajs/mocha.git
- Docs: https://mochajs.org/
| September 2026 | mocha 12.0.2 |