Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: innovating beforeEach and afterEach #53

Merged
merged 1 commit into from
Feb 29, 2024
Merged

feat: innovating beforeEach and afterEach #53

merged 1 commit into from
Feb 29, 2024

Conversation

wellwelwel
Copy link
Owner

In-conde

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

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

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

assert(true, 'Test A');
assert(true, 'Test B');
assert(true, 'Test C');
assert(true, 'Test D');

Exclusive Features

Poku provides three optional methods from both beforeEach and afterEach:

  • .pause()
  • .continue()
  • .reset()
import { assert, beforeEach, afterEach } from 'poku';

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

const before = beforeEach(() => prepareService());
const after = afterEach(() => resetService());

assert.ok(true, 'Test A');
assert.ok(true, 'Test B');

before.pause();

assert.ok(true, 'Test C');
assert.ok(true, 'Test D');

before.continue();

assert.ok(true, 'Test E');

// From now, it will not run beforeEach until you declare it again.
before.reset();

assert.ok(true, 'Test F');

Per test file

Poku brings a simple way to perform a callback before and/or after every test file.

import { poku } from 'poku';

const prepareService = () => new Promise((resolve) => resolve(true));
const resetService = () => new Promise((_, reject) => reject('Yeah'));

await poku('test/unit', {
  beforeEach: prepareService,
  afterEach: resetService,
});
npx poku test/run.test.js

@wellwelwel wellwelwel merged commit 3ea3a12 into main Feb 29, 2024
25 checks passed
@wellwelwel wellwelwel deleted the before-after branch March 1, 2024 09:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant