🕵🏻 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
assertis 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';
strictmethod is available for Node.js 16 onwards, Bun, and Deno. If you use it on unsupported Node.js versions, Poku will use the standardassertinstead.
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