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:
- Created 3 years ago
- Comments:7 (7 by maintainers)
Top 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 >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
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! ThanksReleased with version 2.3.0 of fast-check.
Feel free to re-open 😃