kocha v1.9.1
Kocha v1.1.0
Modern, simpler Mocha clone, no globals, lint friendly
Supports node.js >= active LTS.
:cd: Install
npm install kocha --save-devUse in node.js
Require describe, it etc from kocha, and write tests as in mocha:
test.js:
const { describe, it } = require('kocha')
const assert = require('assert')
const add = (a, b) => a + b
describe('add', () => {
it('adds the given numbers', () => {
const sum = add(12, 13)
assert(sum === 25)
})
})Then run it by kocha command.
./node_modules/.bin/kocha test.jsThis outputs the report like the below:
$ ./node_modules/.bin/kocha test.js
add
✓ adds the given numbers
1 passing (4ms)Use in karma
TBD
APIs
const {
describe,
it,
before,
beforeEach,
after,
afterEach,
timeout,
retries
} = require('kocha')describe(title, callback)
Adds the test suite by the title and callback. In callback function you can add child test suites and/or test cases.
describe.skip(title, callback)
Adds the skipped test suite by the title and callback. The test suites and cases under this suite are all skipped as well.
it(spec, callback)
Adds the skipped test case by the title and callback. callback implements your test case.
it.skip(spec, callback)
Adds the skipped test case by the title and callback.
before(callback)
Adds the before hook to the current suite.
beforeEach(callback)
Adds the beforeEach hook to the current suite.
after(callback)
Adds the after hook to the current suite.
afterEach(callback)
Adds the afterEach hook to the current suite.
timeout(timeout)
Sets the timeout duration to the test cases or the test suites.
retries(n)
Sets the retry count of the test cases or the test suites.
Goals
- Support BDD mode, Spec reporter of mocha in CommonJS environment.
- This includes Karma environment with CommonJS bundler (browserify, webpack).
Non-goals
- Kocha isn't a drop-in replacement of mocha.
- Kocha doesn't support interfaces other than
BDD, likeTDD,QUnit,Exportsetc - Kocha doesn't support standalone mode in browser.
- Kocha's BDD interface is not identical to Mocha's BDD interface. See the below for details.
Differences from mocha
- Kocha doesn't have
this.timeout(ms)API. Usekocha.timeout(ms)API instead. - Kocha doesn't have
this.retries(n)API. Usekocha.retries(n)API instead. - Kocha doesn't have
xdescribeandxit. Instead usedescribe.skipandit.skipresp. - Kocha doesn't have
contextandspecifykeyword. Usedescribeanditresp.
Migration from mocha
For node.js
- Use
kochacommand instead ofmochaor_mochacommand. - Add
const { describe, it, ... } = require('kocha')statement on the top of each mocha test script. - Rewrite
xdescribeandxittodescribe.skipandit.skipresp. if you have any. - Rewrite
this.timeout(N)tokocha.timeout(N)if you have any. - Rewrite
this.retries(N)tokocha.retries(N)if you have any. - Rewrite
contextandspecifytodescribetoitresp. if you have any. - Then your tests should work with kocha.
If the above doesn't work, please file an issue.
For karma
TBD
Name
Kocha (紅茶, pronounced like ko-cha, not like ko-ka) means black tea in Japanese.
License
MIT
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago