Skip to main content
Version: v2.x.x

πŸ§ͺ test

test(message: string, cb: () => void) | test(cb: () => void)

test is a helper to assist you in such cases:

  • Use the beforeEach and afterEach for each test performed
  • Isolate or group your tests in the same file
  • Run tests in the same file in parallel

Basic Usage​

Isolating scopes​

import { test, assert } from 'poku';

test(() => {
const myVar = 'a';

assert.strictEqual(myVar, 'a', 'My first test helper');
});

test(() => {
const myVar = 'b';

assert.strictEqual(myVar, 'b', 'My second test helper');
});

Grouping tests​

import { test, assert } from 'poku';

test(() => {
assert.equal(1 + 1, 2, '1 + 1 should be 2');
assert.equal(2 + 2, 4, '2 + 2 should be 4');
});
import { test, assert } from 'poku';

test('Sum tests', () => {
assert.equal(1 + 1, 2);
assert.equal(2 + 2, 4);
});
import { test, assert } from 'poku';

test('Sum tests', () => {
assert.equal(1 + 1, 2, '1 + 1 should be 2');
assert.equal(2 + 2, 4, '2 + 2 should be 4');
});

Waiting for promises​

import { test } from 'poku';

await test(async () => {
// do anything you want
});

await test(async () => {
// do anything you want
});

Running in parallel​

import { test } from 'poku';

test(async () => {
// do anything you want
});

test(async () => {
// do anything you want
});

Waiting for multiple promises​

import { test } from 'poku';

// do something before

await Promise.all([
test(async () => {
// do anything you want
}),

test(async () => {
// do anything you want
}),
]);

// do something after
tip

You can think on it as beforeAll and afterAll.