mocha-skill
mocha-skill enables you to create well-organized unit tests leveraging Mocha's hierarchical test structure and Chai's expressive assertion library. Build comprehensive test suites with clear describe blocks and individual test cases, then execute them to validate your code's behavior.
mocha-skill teaches you to structure tests using Mocha's describe/it syntax. The describe block organizes related tests into logical groups, while each it block represents a single test case. Within each it block, you write Chai assertions to validate expected behavior. For example, describe('Calculator', () => { it('should add two numbers', () => { expect(add(2, 3)).to.equal(5); }); }); runs a test that checks if your add function returns 5 when given 2 and 3.
AI-generated summary based on this skill's SKILL.md
Decision gist · record as of 2026-07-24
mocha-skill teaches you to structure tests using Mocha's describe/it syntax. The describe block organizes related tests into logical groups, while each it block represents a single test case. Within each it block, you write Chai assertions to validate expected behavior. For example, describe('Calculator', () => { it('should add two numbers', () => { expect(add(2, 3)).to.equal(5); }); }); runs a test that checks if your add function returns 5 when given 2 and 3.
Use it when
- mocha-skill covers Sinon's mocking and stubbing capabilities for isolating dependencies during testing.
- mocha-skill demonstrates testing async patterns including callbacks, promises, and async/await syntax.
Verify before relying
Read SKILL.md below before installing (3 files). Open directory: indexed for reading, not audited.
Install
LambdaTest/agent-skills/mocha-skill · repository language: Python
Open directory. Skills are indexed for reading, not audited. Review a skill's body before installing it.
Frequently asked questions
AI-generated answers based on this skill's SKILL.md and metadata
How do I write mocha tests with describe and it blocks?
mocha-skill teaches you to structure tests using Mocha's describe/it syntax. The describe block organizes related tests into logical groups, while each it block represents a single test case. Within each it block, you write Chai assertions to validate expected behavior. For example, describe('Calculator', () => { it('should add two numbers', () => { expect(add(2, 3)).to.equal(5); }); }); runs a test that checks if your add function returns 5 when given 2 and 3.
How do I mock functions with sinon in my mocha tests?
mocha-skill covers Sinon's mocking and stubbing capabilities for isolating dependencies during testing. Sinon lets you replace real function implementations with test doubles. You can create stubs that return predetermined values, spies that track function calls, or mocks that verify specific interactions occurred. For instance, const stub = sinon.stub(obj, 'method').returns(42); replaces obj.method with a stub that always returns 42, letting you test code that depends on that method without executing its actual logic.
What is the best way to test asynchronous code like promises and async/await with mocha?
mocha-skill demonstrates testing async patterns including callbacks, promises, and async/await syntax. Mocha automatically handles promises returned from test functions, and async/await tests work seamlessly—just declare your it callback as async and await promise-based operations. For callbacks, use Mocha's done parameter: it('loads data', (done) => { fetchData((err, result) => { expect(result).to.equal('data'); done(); }); }); For promises: it('loads data', () => { return fetchData().then(result => { expect(result).to.equal('data'); }); }); Mocha waits for promise resolution before marking the test complete.
How do I configure mocha test runner with hooks and watch mode?
mocha-skill teaches you to set up Mocha with lifecycle hooks like beforeEach, afterEach, before, and after to run setup and teardown logic around your tests. Use beforeEach to initialize test fixtures before each test runs, and afterEach to clean up afterward. Enable watch mode by running mocha --watch, which automatically reruns tests whenever your files change. Configure timeouts with mocha --timeout 5000 to set a 5-second limit per test, and use mocha --grep 'pattern' to filter and run only tests matching your pattern.
What are chai assertions and how do I use expect syntax?
mocha-skill covers Chai's expressive assertion library that pairs with Mocha for readable test validation. The expect syntax lets you chain readable assertions: expect(value).to.equal(5), expect(array).to.include(item), expect(obj).to.have.property('name'), expect(fn).to.throw(Error). Chai assertions support deep equality checks with expect(obj).to.deep.equal(expectedObj), type checking with expect(value).to.be.a('string'), and complex conditions. These fluent assertions make test code self-documenting and failures easy to diagnose.
What are best practices and anti-patterns when using mocha-skill for testing?
mocha-skill highlights key best practices: write one assertion per test when possible for clarity, use descriptive test names that explain what behavior is being validated, always restore stubs and spies in afterEach hooks to prevent test pollution, and avoid testing implementation details—focus on observable behavior instead. Anti-patterns to avoid include writing tests that depend on execution order, creating overly broad describe blocks that mix unrelated tests, forgetting to handle async properly which causes tests to pass falsely, and leaving stubs active between tests which causes unexpected side effects. Keep tests isolated, fast, and maintainable.
SKILL.md
Rendered from the published skill. Quoted content, verbatim.
Mocha Testing Skill
Core Patterns
Basic Test with Chai
const { expect } = require('chai');
describe('Calculator', () => {
let calc;
beforeEach(() => { calc = new Calculator(); });
it('should add two numbers', () => {
expect(calc.add(2, 3)).to.equal(5);
});
it('should throw on divide by zero', () => {
expect(() => calc.divide(10, 0)).to.throw('Division by zero');
});
});
Chai Assertions
expect(value).to.equal(5);
expect(arr).to.have.lengthOf(3);
expect(obj).to.have.property('name');
expect(str).to.include('hello');
expect(fn).to.throw(Error);
expect(arr).to.deep.equal([1, 2, 3]);
expect(obj).to.deep.include({ name: 'Alice' });
Sinon Mocking
```javascript const sinon = require('sinon');
describe('UserService', () => { let
(truncated - see the full file via the links below)
File tree — 3 files
mocha-skill/SKILL.md
mocha-skill/reference/advanced-patterns.md
mocha-skill/reference/playbook.md
Let your AI agent find skills like this
Example. Real query, live index.
You found this page by searching. An agent finds it by wishing: SkillFed indexes 56,283 agent skills by what they can do, searchable in plain language.
wish › “Write and structure unit tests using Mocha's describe/it syntax with Chai assertions”
Give your agent the search over MCP, or paste the wish link into any chat. No install? Search from any chat →
Related skills
jasmine-skill enables you to craft well-organized unit tests following Jasmine's behavior-driven development patterns. Use describe blocks to group related tests, it blocks to define individual test cases, and expect assertions to validate your code's behavior. Perfect for developers building robust test suites with clear, readable test structure.
This skill covers the essentials of selecting, configuring, and deploying test frameworks to automate your testing workflows. You'll learn practical techniques for structuring test suites, writing effective test cases, and integrating frameworks into your development pipeline to catch bugs early and maintain code quality.
This skill enables you to generate and author Nemo.js end-to-end tests for web applications, streamlining test automation workflows. Leverage AI-powered test generation to accelerate your QA processes and reduce manual testing overhead.
This skill equips you to write robust JUnit 5 tests in Java, from basic assertions and exception handling to parameterized test cases and Mockito-driven mocking. It covers lifecycle management, nested test organization, and anti-patterns to avoid, with quick reference commands for Maven and Gradle execution.
selenium-skill enables you to create robust Selenium WebDriver test automation scripts in your preferred programming language through intelligent code synthesis. Streamline browser testing by leveraging AI to generate production-ready test logic, reducing manual scripting overhead and accelerating test suite development.
karma-skill enables you to initialize and configure Karma, a powerful test runner that works across multiple browsers and testing frameworks. Automate your test environment setup and launcher configuration to accelerate testing cycles.