Skip to main content
Version: v3.x.x

In-Code

beforeEach and afterEach​

Both beforeEach, afterEach are recommended for tests that consume a particular global state for each test.
For example, by populating or resetting a database before and/or after multiple assertions.

Basic usage​

import { test, beforeEach, afterEach } from 'poku';

const prepareService = () => true;
const resetService = () => true;

beforeEach(() => prepareService());

afterEach(() => resetService());

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

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

By using promises​

import { test, beforeEach, afterEach } from 'poku';

const prepareService = () => new Promise((resolve) => resolve(true));

const resetService = () => new Promise((resolve) => resolve(true));

beforeEach(async () => await prepareService());
afterEach(async () => await resetService());

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

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

You can overwriting both beforeEach and afterEach by declaring them again anytime.

Poku provides three optional methods from both beforeEach and afterEach:

  • .pause()
  • .continue()
  • .reset()