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

Add beforeEach & afterEach hooks #9

Closed
lukeed opened this issue Jul 8, 2020 · 2 comments · Fixed by #11
Closed

Add beforeEach & afterEach hooks #9

lukeed opened this issue Jul 8, 2020 · 2 comments · Fixed by #11
Assignees
Labels
Milestone

Comments

@lukeed
Copy link
Owner

lukeed commented Jul 8, 2020

Currently, suite.before and suite.after are tied to the suite's lifecycle.
This would be added to run before/after each test block within the suite.

test.before(() => {
  console.log('SETUP');
});

test.after(() => {
  console.log('CLEANUP');
});

test.beforeEach(() => {
  console.log('>> BEFORE');
});

test.afterEach(() => {
  console.log('>> AFTER');
});

// ---

test('foo', () => {
  console.log('>>>> TEST: FOO');
});

test('bar', () => {
  console.log('>>>> TEST: BAR');
});

test.run();

// SETUP
// >> BEFORE
// >>>> TEST: FOO
// >> AFTER
// >> BEFORE
// >>>> TEST: BAR
// >> AFTER
// CLEANUP
@lukeed lukeed added the maybe label Jul 8, 2020
@lukeed lukeed self-assigned this Jul 9, 2020
@lukeed
Copy link
Owner Author

lukeed commented Jul 9, 2020

What about before.each() and after.each()?

The existing before() and after() hooks remain the same, but this way it nests the each modifier onto each hook type.

//cc @hyanmandian

@hyanmandian
Copy link
Contributor

Awesome idea @lukeed , I agree with you, in that case, a chainable approach is better.

@lukeed lukeed added this to the 0.2.0 milestone Jul 9, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants