question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Global beforeEach/afterEach

See original GitHub issue

🚀 Feature Request

Similarly to test runners like jest, it would be great if there was a way of setting global beforeEach/afterEach functions that get executed before/after a property is run.

Motivation

When using libraries like react-testing-library, it is recommended to call its cleanup method between tests to prevent issues like memory leaks. While this is done automatically for popular test runners, I need to manually do it for fast-check tests. https://testing-library.com/docs/react-testing-library/api#cleanup

Example

Currently, I have to do this:

fc.property(...).beforeEach(cleanup);

Ideally, I would want to do something like this:

// In jest.setup.ts file
fc.configureGlobal({
    beforeEach: cleanup,
});
// Then I could skip the `beforeEach` from properties
fc.property(...);

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:7 (7 by maintainers)

github_iconTop GitHub Comments

1reaction
brapifracommented, Aug 17, 2020

Oh okay, there are two versions of run, one async and other sync. Makes sense to have 4 options then. I’ll start looking into it as soon as I can! Thanks

0reactions
dubzzzcommented, Sep 9, 2020

Released with version 2.3.0 of fast-check.

Feel free to re-open 😃

Read more comments on GitHub >

github_iconTop Results From Across the Web

Running a global test setup before each test in Jest
I know that I can use beforeEach to accomplish this within a single test file, but I want to do it globally for...
Read more >
Globals
beforeEach (fn, timeout) ​ ... Runs a function before each of the tests in this file runs. If the function returns a promise...
Read more >
Globals · Jest
afterEach (fn) # ... Runs a function after each one of the tests in this file completes. If the function returns a promise,...
Read more >
before/afterEach across test files · Issue #5455 · facebook/jest
It would be useful to be able to specify a 'global' type of beforeEach and afterEach that would apply across tests in every...
Read more >
global before/after/beforeEach/afterEach?
Is there any way to do a global (i.e. across all files in ./tests/) before/after/beforeEach/afterEach? Let's say my tests dir looks like:.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found