π΅π» Assert
Poku includes the assert
method native from Node.js, keeping everything as it is, but providing human readability.
It supports both Bun and Deno.
The
assert
is used to write tests and verify if your code works as expected by comparing values and throwing errors, otherwise π§π»βπ
Migrating to Poku's assert
β
But only if you want to, of course.
Default assertions:
- import assert from 'node:assert';
+ import { assert } from 'poku';
Strict assertions:
- import assert from 'node:assert/strict';
+ import { strict as assert } from 'poku';
strict
method is available for Node.js 16 onwards, Bun, and Deno. If you use it on unsupported Node.js versions, Poku will use the standardassert
instead.
assert(true, "It's true π§ͺ");
assert.strictEqual(1, '1', 'Poku will describe it and show an error π·');
// ...
Poku's assert
will use the message exactly as it is when using describe
and it
.
Your Poku is waiting for you π·β¨
π To learn about assertions, see the quick tutorial: From a basic assertion test to its execution.
Available Methodsβ
import { assert } from 'poku';
// import { strict as assert } from 'poku';
Positive Assertion
Truthyβ
assert(value[, message])
assert.ok(value[, message])
Equalityβ
assert.equal(actual, expected[, message])
assert.strictEqual(actual, expected[, message])
Deep Equalityβ
assert.deepEqual(actual, expected[, message])
assert.deepStrictEqual(actual, expected[, message])
Matchingβ
assert.match(string, regexp[, message])
Successβ
assert.doesNotReject(asyncFn[, error][, message])
assert.doesNotThrow(fn[, error][, message])
Negative Assertion
Inequalityβ
assert.notEqual(actual, expected[, message])
assert.notStrictEqual(actual, expected[, message])
Deep Inequalityβ
assert.notDeepEqual(actual, expected[, message])
assert.notDeepStrictEqual(actual, expected[, message])
Non-Matchingβ
assert.doesNotMatch(string, regexp[, message])
Failureβ
assert.rejects(asyncFn[, error][, message])
assert.throws(fn[, error][, message])
Error Handling
You can follow the assert documentation from Node.js's documentation.
For Node.js, the assert.match
and assert.doesNotMatch
methods are available from version 12 or higher.
To compile tests using assert
with TypeScript, you may will need to install @types/node:
npm i -D @types/node