Mocha JavaScript Test Framework
github.com
2
Leaving SiteNav
External Link Disclaimer
You are about to visit github.com. This website is not operated by us. We are not responsible for its content or privacy practices.
About this website
Mocha is a free and open-source JavaScript test framework that runs on Node.js and in the browser, designed to make asynchronous testing simple and fun. Created by TJ Holowaychuk (also the creator of Express.js) in 2011 and currently maintained by the Mocha team, Mocha is one of the most popular test frameworks in the JavaScript ecosystem. Key features: test structure: organize tests using BDD (Behavior-Driven Development) style (describe, it, before, after, beforeEach, afterEach) or TDD (Test-Driven Development) style (suite, test, setup, teardown). The BDD interface is the default and most widely used. describe blocks group related tests, while it blocks define individual test cases. Asynchronous testing: Mocha excels at async testing. Tests can signal completion via callbacks (done), promises (return a Promise), or async/await. Mocha waits for the async operation to complete before moving to the next test, with configurable timeouts (default 2000ms). Hooks: before (runs once before all tests), after (runs once after all tests), beforeEach (runs before each test), afterEach (runs after each test). Hooks can be async and are used for setup and teardown. Pending tests: tests marked with it.skip or xit are skipped (pending), allowing work-in-progress without failing the suite. Exclusive tests: it.only runs only that test, useful for debugging a single test case. Assertions: Mocha does not include an assertion library. It integrates with Node's assert module, Chai (expect, should, assert style), should.js, or expect.js. Reporters: multiple built-in reporters including spec (hierarchical, default), dot (minimalist), TAP, JSON, HTML, list, min, Nyan, and Markdown. Custom reporters can be written. Integration: works with Sinon.js (mocks, stubs, spies), Istanbul/nyc (code coverage), Karma (browser testing), and Playwright/Cypress. File watching with --watch. JavaScript. MIT.
Statistics
2
Views
0
Clicks
0
Like
0
Dislike