Skip to main content
Version: v2.x.x

πŸ•΅πŸ» 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 standard assert instead.
assert(true, "It's true πŸ§ͺ");
assert.strictEqual(1, '1', 'Poku will describe it and show an error 🐷');
// ...
tip

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

Falsy​

assert.ifError(value);
  • Tests for a error value, useful in callbacks

Forces a failure​

assert.fail([message]);

You can follow the assert documentation from Node.js's documentation.

note

For Node.js, the assert.match and assert.doesNotMatch methods are available from version 12 or higher.

info

To compile tests using assert with TypeScript, you may will need to install @types/node:

npm i -D @types/node