agentsclimarketplace

Mocha

Skill G1Joshi/Agent-Skills/skills/testing/mocha

Mocha JavaScript test framework. Use for Node.js testing.From its SKILL.md

Install
npx -y skills add G1Joshi/Agent-Skills --skill mocha

Assembled from the repository path, not quoted from the project. Check it against their README if it does not work.

One thing to look at

  • 10 stars10 stars. Stars are a popularity signal and not a quality one, but at this level it is likely that nobody has read this closely except its author, and you would be relying on your own review.

SKILL.md

1.7 KB, 428 tokens by cl100k_base, as published. Nobody here has run it

Mocha

Mocha is a flexible JavaScript test framework. Unlike Jest, it does not come with an assertion library, mocking, or snapshotting built-in. It is a runner that allows you to choose your own tools (usually Chai + Sinon).

When to Use

  • Flexibility: You want to pick your assertion library (Chai, Should.js).
  • Node.js Backends: standard in many Express/NestJS (legacy) setups.
  • Asynchronous Testing: Historically strong support for async (though standard now).

Quick Start

// npm install --save-dev mocha chai
const assert = require("chai").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);
    });
  });
});

Core Concepts

BDD Interface

describe (suite), it (test), before, after, beforeEach, afterEach.

Hooks

Mocha allows defining hooks at the root level or inside suites to set up/tear down environments.

Async support

Use async/await in the it block callback.

it("should save user", async function () {
  const user = new User("tobi");
  await user.save();
});

Best Practices (2025)

Do:

  • Use .only and .skip: Useful during development to run a single test (it.only(...)).
  • Use nyc (Istanbul): For code coverage (since Mocha doesn't have it built-in).

Don't:

  • Don't use arrow functions (() => {}) if you need this.timeout() or this.slow(). Mocha binds the test context to this.

References

What ships with it

Read from the repository

Just SKILL.md. No reference files, no scripts.

Keep looking

Skills are one crate of 326,871. Ordering is by how many stacks a row turns up in, so the top of any crate is what has actually been picked rather than what has the most stars.