-
Notifications
You must be signed in to change notification settings - Fork 220
Language JavaScript
- Node 8.x
- Node 10.x
Starting from Node 10.x, Mocha is used instead of our custom test framework. Codewars' assertion methods are still available for now.
For new tests, using Chai is recommended.
You can use it by requiring "chai":
const chai = require("chai");
// const assert = chai.assert;
// const expect = chai.expect;
If the failure output for deep equality is truncated, chai.config.truncateThreshold
can be adjusted. Setting this to 0
will disable the truncation.
const chai = require("chai");
const assert = chai.assert;
chai.config.truncateThreshold=0;
describe("Example", function() {
it("should test", function() {
assert.strictEqual(1 + 1, 2);
assert.deepEqual([2,2], [2,-(-2)]);
});
});
Each it
represents a test case and stops at the first assertion failure.
If you want to have a test case for each input, you can write tests like the following:
// [input, expected]
const tests = [
["foo", "Foo"],
["bar", "Bar"],
];
describe("Example", function() {
for (const [input, expected] of tests) {
it(`input: ${JSON.stringify(input)}`, function() {
assert.strictEqual(example(input), expected);
});
}
});
When the input is too much for a test case name, you can output it inside a test case:
describe("Example", function() {
for (let i = 0; i < tests.length; ++i) {
it(`example test ${i + 1}`, function() {
const [input, expected] = tests[i];
console.log(`<LOG::-input>${JSON.stringify(input)}`);
assert.strictEqual(example(input), expected);
});
}
});
Prefixing with <LOG::-LABEL>
will put the message inside a container with LABEL
. The -
makes it collapsed by default.
12 seconds
NOTE: Module versions are locked but may be updated. If an update happens, existing kata may need to be manually updated.
- bignumber.js
- bluebird
- brain
- canvas
- chai
- chai-http
- chai-spies
- cheerio
- enzyme
- escape-html
- expect
- express
- faker
- jsdom
- lodash
- mocha
- moment
- mongodb
- mongoose
- pg
- q
- ramda
- react
- react-addons-test-utils
- react-dom
- react-redux
- react-test-renderer
- redis
- redux
- should
- sinon
- sqlite3
- underscore
- web3
- ganache-core
- sqlite3
- redis
- mongodb
javascript