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-dev
Use 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.js
This 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
,Exports
etc - 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
xdescribe
andxit
. Instead usedescribe.skip
andit.skip
resp. - Kocha doesn't have
context
andspecify
keyword. Usedescribe
andit
resp.
Migration from mocha
For node.js
- Use
kocha
command instead ofmocha
or_mocha
command. - Add
const { describe, it, ... } = require('kocha')
statement on the top of each mocha test script. - Rewrite
xdescribe
andxit
todescribe.skip
andit.skip
resp. 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
context
andspecify
todescribe
toit
resp. 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
6 years ago
6 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago