docs-next/src/content/docs/getting-started.mdx
import { PackageManagers } from "starlight-package-managers";
First, install the mocha package as a devDependency using your favorite package manager:
:::note
As of v11.0.0, Mocha requires Node.js ^18.18.0 || ^20.9.0 || >=21.1.0.
:::
Create the following example.test.js file under a test/ directory:
// test/example.test.js
import { assert } from "node:assert";
describe("Array", function () {
describe("#indexOf()", function () {
it("should return -1 when the value is not present", function () {
assert.equal([1, 2, 3].indexOf(4), -1);
});
});
});
Now, run npx mocha to execute the Mocha package on the newly created test file:
npx mocha
You should see passing output like:
Array
#indexOf()
✓ should return -1 when the value is not present
1 passing (9ms)
test scriptMost projects include a package.json "test" script:
// package.json
{
"scripts": {
"test": "mocha"
}
}
You can then run that script with your favorite package manager:
<PackageManagers type="run" pkg="test" />See:
mochaYou can see real live example code in our example repositories: