Micro-Jest is a tiny JavaScript testing framework for Kaluma. It is distilled version of the original Jest project.
Install package with NPM.
$ npm install https://github.com/niklauslee/micro-jest --saveHere is a simple example. Different from Jest, you have to call done() always even if the test case is synchronous.
const { test, expect, start } = require("micro-jest");
function sum(a, b) {
return a + b;
}
test("adds 1 + 2 to equal 3", (done) => {
expect(sum(1, 2)).toBe(3);
done(); // should be called
});
start(); // start to testMicro-Jest provides various matchers to test values. toBe() is used to test a value with exact equality.
test("1 + 1 = 2", (done) => {
expect(1 + 1).toBe(2);
done();
});Here is the matchers provided.
expect(value).toBe(value)expect(value).notToBe(value)expect(value).toBeTruthy()expect(value).toBeFalsy()expect(number).toBeGreaterThan(number)expect(number).toBeGreaterThanOrEqual(number)expect(number).toBeLessThan(number)expect(number).toBeLessThanOrEqual(number)expect(array).toContain(value)expect(array).notToContain(value)expect(string).toMatch(regex)expect(string).notToMatch(regex)expect(function).toThrow([message])expect(function).notToThrow()
To run all test cases you have to call jest.start().
However sometimes you want to run a particular test case rather than all test cases. You can do it by calling start() with a number of test case.
jest.start(0); // Run the first test case.
jest.start(3); // Run the 4-th test case.
jest.start(); // Run all the test cases.If you catch an error you can pass it to done() callback.
// async
test('adds 1 + 2 to equal 3', (done) => {
someAsyncFunction(err => {
if (err) {
done(err);
} else {
expect(...).toBe(...);
done();
}
})
});
// sync
test('adds 1 + 2 to equal 3', (done) => {
try {
someSyncFunction();
done();
} catch(err) {
done(err);
}
});