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.