value that is coerced to true
Optionalmessage: stringerror message to display when test is false
OptionalErrorClass: ErrorConstructorerror class to throw
assert(true, 'this is true');
assert(false, 'this is false');
assert(() => true, 'this is true');
assert(() => false, 'this is false');
const SomeErrorClass = class extends Error {
constructor(message: string) {
super(message);
}
}
const someFunc = () => {
assert(true, 'this is true', SomeErrorClass);
assert(false, 'this is false', SomeErrorClass);
assert(() => true, 'this is true', SomeErrorClass);
assert(() => false, 'this is false', SomeErrorClass);
// some logic
}
someFunc();
Asserts that a value is true. Even though NodeJS has an
assertbuiltin library, this aims to bring a single API for asserting across all environments.