Skip to main content
Version: v3.x.x

Promises

The use of native JavaScript syntax in tests is one of the major differences between Poku and other test runners, which is what makes it possible to use it on multiple platforms.

tip

It's not necessary to use await for tests that aren't asynchronous.

Here are some examples of sequential and concurrent tests in the same file plus how to perform an action after all the tests have been completed:

Running async tests in the same file in parallel​

import { test, assert, sleep } from 'poku';

test(async () => {
const actual = 1;
const expected = 1;

await sleep(2000);

assert.strictEqual(actual, expected);
});

test(async () => {
const actual = 2;
const expected = 2;

await sleep(1000);

assert.strictEqual(actual, expected);
});

Running async tests in the same file sequentially (await top-level)​

import { test, assert, sleep } from 'poku';

await test(async () => {
const actual = 1;
const expected = 1;

await sleep(2000);

assert.strictEqual(actual, expected);
});

await test(async () => {
const actual = 2;
const expected = 2;

await sleep(1000);

assert.strictEqual(actual, expected);
});

Running async tests in the same file sequentially​

import { describe, it, assert, sleep } from 'poku';

describe(async () => {
await it(async () => {
const actual = 1;
const expected = 1;

await sleep(2000);

assert.strictEqual(actual, expected);
});

await it(async () => {
const actual = 2;
const expected = 2;

await sleep(1000);

assert.strictEqual(actual, expected);
});
});

Waiting for all the tests to run a post step​

import { describe, it, assert, sleep } from 'poku';

describe(async () => {
console.log('Printing it before all tests πŸƒπŸ»β€β™€οΈ');

await Promise.all([
test(async () => {
const actual = 1;
const expected = 1;

await sleep(2000);

assert.strictEqual(actual, expected);
}),

test(async () => {
const actual = 2;
const expected = 2;

await sleep(1000);

assert.strictEqual(actual, expected);
}),
]);

console.log('Printing it after all tests 😴');
});
tip

For multiple asynchronous describe or test, you can also use await to run them sequentially.


Be careful

When using asynchronous beforeEach or afterEach, it's necessary to use await even if the test or it helpers doesn't have any asynchronous events.

note

If you find any typos, feel free to open a Pull Request correcting them.