Kocha

raw JSON →
1.9.1 verified Fri May 01 auth: no javascript

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.

error ReferenceError: describe is not defined
cause Using Mocha globals without importing Kocha's exports.
fix
Add 'const { describe, it } = require('kocha')' at the top of your test file.
error TypeError: describe.skip is not a function
cause Attempting to use xdescribe (undefined) instead of describe.skip.
fix
Replace xdescribe with describe.skip.
error Error: timeout is not a function
cause Calling this.timeout inside a test callback; Kocha does not support that.
fix
Call timeout(n) directly from require('kocha') at suite level.
error Cannot find module 'kocha'
cause Kocha is not installed in node_modules.
fix
Run 'npm install kocha --save-dev' in your project directory.
breaking Kocha does not support this.timeout(ms) or this.retries(n); use the exported timeout() and retries() functions instead.
fix Call timeout(n) and retries(n) directly from require('kocha') at the suite level.
breaking Kocha does not support xdescribe, xit, context, or specify; use describe.skip, it.skip, describe, it respectively.
fix Replace xdescribe with describe.skip, xit with it.skip, context with describe, specify with it.
gotcha Kocha is not a drop-in replacement for Mocha; it lacks TDD, QUnit, and standalone browser mode. Requires explicit imports of describe, it, etc.
fix Imports must be added to each test file; tests expecting global Mocha functions will fail.
gotcha The command-line interface is 'kocha', not 'mocha'. Ensure node_modules/.bin/kocha is used to run tests.
fix Run tests using './node_modules/.bin/kocha test.js' or add a script in package.json: 'scripts': { 'test': 'kocha test.js' }.
npm install kocha
yarn add kocha
pnpm add kocha

Shows basic BDD test suite with hooks, assertions, and skip using Kocha.

const { describe, it, before, after, beforeEach, afterEach, timeout, retries } = require('kocha')
const assert = require('assert')

let value
beforeEach(() => {
  value = 42
})

describe('example', () => {
  it('should return 42', () => {
    assert.strictEqual(value, 42)
  })

  it.skip('pending test', () => {
    // skipped
  })
})

// run with: ./node_modules/.bin/kocha test.js