API Documentation
To use assertion functions, you must pass the current test context (
this
) as the first argument.
Jsert is a lightweight JavaScript library for rapid creation and execution of tests in both Browser and Node.js.
const jsert = new Jsert({ group: "Sample" });
jsert.test("Check equality", function() {
jsert.passWhenEquals(this, 1 + 1, 2);
});
jsert.run();
To use assertion functions, you must pass the current test context (
this
) as the first argument.
Passes if the expression evaluates to true.
jsert.passWhen(this, typeof name === "string")
Strict equality (===) check.
jsert.passWhenEquals(this, status, 200)
Passes if the value is truthy.
jsert.passWhenTruthy(this, user.active)
Passes if the value is falsy.
jsert.passWhenFalsy(this, errorOccurred)
Deep structural equality check for objects and arrays.
jsert.passWhenMatch(this, user, { name: "John", id: 1 })
Checks against typeof, or "array" for Array objects.
jsert.passWhenTypeIs(this, items, "array")
Passes if length is 0.
jsert.passWhenEmpty(this, [])
Passes if item is found in array/string.
jsert.passWhenIncludes(this, ["a", "b"], "a")
Validates length property.
jsert.passWhenHasLength(this, [1, 2], 2)
Strict inequality (!==) check.
jsert.passWhenNotEquals(this, 5, 10)
Registers a new test case.
Executes the test suite.
Clears tests and results.