Fast, Flexible
Unit Testing.

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();

API Documentation

To use assertion functions, you must pass the current test context ( this ) as the first argument.

passWhen(test, condition)

Passes if the expression evaluates to true.

jsert.passWhen(this, typeof name === "string")

passWhenEquals(test, actual, expected)

Strict equality (===) check.

jsert.passWhenEquals(this, status, 200)

passWhenTruthy(test, actual)

Passes if the value is truthy.

jsert.passWhenTruthy(this, user.active)

passWhenFalsy(test, actual)

Passes if the value is falsy.

jsert.passWhenFalsy(this, errorOccurred)

passWhenMatch(test, obj1, obj2)

Deep structural equality check for objects and arrays.

jsert.passWhenMatch(this, user, { name: "John", id: 1 })

passWhenTypeIs(test, actual, type)

Checks against typeof, or "array" for Array objects.

jsert.passWhenTypeIs(this, items, "array")

passWhenEmpty(test, collection)

Passes if length is 0.

jsert.passWhenEmpty(this, [])

passWhenIncludes(test, array, item)

Passes if item is found in array/string.

jsert.passWhenIncludes(this, ["a", "b"], "a")

passWhenHasLength(test, collection, length)

Validates length property.

jsert.passWhenHasLength(this, [1, 2], 2)

passWhenNotEquals(test, actual, expected)

Strict inequality (!==) check.

jsert.passWhenNotEquals(this, 5, 10)

Core API

test(name, fn)

Registers a new test case.

run()

Executes the test suite.

reset()

Clears tests and results.