Simple Test utility.
runmessagenpm i @jlongyam/test -D
test/test.js
import Test from "@jlongyam/test";
// Only 4 keywords
const { describe, it, assert } = Test();
describe("Test", () => {
// Container
it(() => {
// Section
assert(2 + 3 === 5); // True
});
it(() => {
assert(-1 + 5 === 5); // False
});
it(() => {
assert(0 + 0 === 0);
});
});
package.json:
"scripts": {
"test": "node ./test/test.js"
}
npm test
Test
✔ should 5
✖ should 4 - Expected false
✔ should 0
How to test Array or Object:
Just like console.assert, comparing using === will fail,
There are two method:
String(A) === String(B)[A,B] bracket.Example:
describe("Test", () => {
it("assert ([a, b])", () => {
let a = [1, 2];
let b = [1, 2, 3];
a.push(3);
// PASS
assert([a, b]);
});
it("assert (a === b)", () => {
let a = [1, 2];
let b = [1, 2, 3];
a.push(3);
// FAIL
assert(a === b);
});
it("assert (String(a) === String(b))", () => {
let a = [1, 2];
let b = [1, 2, 3];
a.push(3);
// PASS
assert(String(a) === String(b));
});
});
More usage see DOCS
| Name | Version |
|---|---|
| IE | 8+ |
| Safari | 5+ |
| Firefox | 52+ |
| Chrome | 50+ |
itthe message argument is optional, example:
it(() => {
let one = { value: "ONE" };
let two = { value: "TWO" };
assert([one, two]); // <- report chunk
});
It will reported assert section automatically: