{"id":25839,"library":"kocha","title":"Kocha","description":"Kocha (v1.9.1) is a modern, simpler clone of Mocha for JavaScript testing in Node.js. It supports BDD-style test syntax (describe/it/beforeEach/afterEach) without globals, making it lint-friendly. It requires explicit imports from the 'kocha' package. Kocha has no dependencies and uses CommonJS modules. It offers timeout and retries as explicit API calls rather than via 'this'. It is maintained with release cadence as needed. Key differentiators: no globals, no standalone browser mode, no TDD/QUnit interfaces, intentionally simpler than Mocha.","status":"active","version":"1.9.1","language":"javascript","source_language":"en","source_url":"https://github.com/kt3k/kocha","tags":["javascript","kocha","mocha","test","bdd","tdd"],"install":[{"cmd":"npm install kocha","lang":"bash","label":"npm"},{"cmd":"yarn add kocha","lang":"bash","label":"yarn"},{"cmd":"pnpm add kocha","lang":"bash","label":"pnpm"}],"dependencies":[],"imports":[{"note":"CommonJS destructuring import is standard; use require('kocha') to get all exports.","wrong":"const describe = require('kocha').describe;","symbol":"describe","correct":"const { describe } = require('kocha')"},{"note":"Same as describe, destructure from require call.","wrong":"const it = require('kocha').it;","symbol":"it","correct":"const { it } = require('kocha')"},{"note":"Hook functions are exported individually.","wrong":"const beforeEach = require('kocha').beforeEach;","symbol":"beforeEach","correct":"const { beforeEach } = require('kocha')"},{"note":"Exported as a function, not attached to 'this' like in Mocha.","wrong":"timeout = require('kocha').timeout;","symbol":"timeout","correct":"const { timeout } = require('kocha')"}],"quickstart":{"code":"const { describe, it, before, after, beforeEach, afterEach, timeout, retries } = require('kocha')\nconst assert = require('assert')\n\nlet value\nbeforeEach(() => {\n  value = 42\n})\n\ndescribe('example', () => {\n  it('should return 42', () => {\n    assert.strictEqual(value, 42)\n  })\n\n  it.skip('pending test', () => {\n    // skipped\n  })\n})\n\n// run with: ./node_modules/.bin/kocha test.js","lang":"javascript","description":"Shows basic BDD test suite with hooks, assertions, and skip using Kocha."},"warnings":[{"fix":"Call timeout(n) and retries(n) directly from require('kocha') at the suite level.","message":"Kocha does not support this.timeout(ms) or this.retries(n); use the exported timeout() and retries() functions instead.","severity":"breaking","affected_versions":">=0.0.0"},{"fix":"Replace xdescribe with describe.skip, xit with it.skip, context with describe, specify with it.","message":"Kocha does not support xdescribe, xit, context, or specify; use describe.skip, it.skip, describe, it respectively.","severity":"breaking","affected_versions":">=0.0.0"},{"fix":"Imports must be added to each test file; tests expecting global Mocha functions will fail.","message":"Kocha is not a drop-in replacement for Mocha; it lacks TDD, QUnit, and standalone browser mode. Requires explicit imports of describe, it, etc.","severity":"gotcha","affected_versions":">=0.0.0"},{"fix":"Run tests using './node_modules/.bin/kocha test.js' or add a script in package.json: 'scripts': { 'test': 'kocha test.js' }.","message":"The command-line interface is 'kocha', not 'mocha'. Ensure node_modules/.bin/kocha is used to run tests.","severity":"gotcha","affected_versions":">=0.0.0"}],"env_vars":null,"last_verified":"2026-05-01T00:00:00.000Z","next_check":"2026-07-30T00:00:00.000Z","problems":[{"fix":"Add 'const { describe, it } = require('kocha')' at the top of your test file.","cause":"Using Mocha globals without importing Kocha's exports.","error":"ReferenceError: describe is not defined"},{"fix":"Replace xdescribe with describe.skip.","cause":"Attempting to use xdescribe (undefined) instead of describe.skip.","error":"TypeError: describe.skip is not a function"},{"fix":"Call timeout(n) directly from require('kocha') at suite level.","cause":"Calling this.timeout inside a test callback; Kocha does not support that.","error":"Error: timeout is not a function"},{"fix":"Run 'npm install kocha --save-dev' in your project directory.","cause":"Kocha is not installed in node_modules.","error":"Cannot find module 'kocha'"}],"ecosystem":"npm","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}