← 返回命令列表

Linux command

mocha 命令

文本

复制后可按需替换文件名、目录或参数。

常用示例

Run tests

mocha

Run specific file

mocha [test/spec.js]

Watch mode

mocha --watch

Run with grep

mocha --grep "[pattern]"

Reporter style

mocha --reporter [spec]

Recursive tests

mocha --recursive

说明

mocha is a JavaScript test framework. It runs in Node.js and browsers. The tool provides BDD/TDD testing styles. Supports async tests and many reporters.

参数

--watch
Watch for changes.
--grep _PATTERN_
Filter tests.
--reporter _NAME_
Output format.
--recursive
Include subdirectories.
--timeout _MS_
Test timeout.
--help
Display help information.

FAQ

What is the mocha command used for?

mocha is a JavaScript test framework. It runs in Node.js and browsers. The tool provides BDD/TDD testing styles. Supports async tests and many reporters.

How do I run a basic mocha example?

Run `mocha` in a terminal, then adjust file names, paths, flags, or remote targets for your system.

What does --watch do in mocha?

Watch for changes.