Clear and concise description of the problem
Inspired by other test runners, I wish to have the ability to wrap multiple tests in a function.
This differes from (and is more powerful than) using beforeEach and afterEach because we can use functionality that rely on closures.
Common usecases:
- Wrapping tests in database transactions (for speed and consistency).
decorateEach((runTest) => {
database.transaction(() => {
await runTest();
});
});
- Custom benchmarking of time / memory etc:
decorateEach((runTest) => {
rbenchmark.report(() => {
await runTest();
});
});
- Freezing time by mocking Date and Date.now:
decorateEach((runTest) => {
dateMocker.setTime("2023-01-01", () => {
await runTest();
});
});
I propose that the feature should be implemented such that common decorators can be applied either to all tests, or to all tests within a describe blocks.
If the team agrees the this feature is valuable, I have been allowed by my employer that I can spend work hours implementing it.
Suggested solution
I propose to use an API such as the one shown above. Suggestions for alternative naming etc are more than welcome.
Alternative
I know of no good alternative. One could use Typescripts Decorators, but that would require adding in a decorator for every test.
Additional context
This has also been requested here:
#3232
Validations
Clear and concise description of the problem
Inspired by other test runners, I wish to have the ability to wrap multiple tests in a function.
This differes from (and is more powerful than) using
beforeEachandafterEachbecause we can use functionality that rely on closures.Common usecases:
I propose that the feature should be implemented such that common decorators can be applied either to all tests, or to all tests within a describe blocks.
If the team agrees the this feature is valuable, I have been allowed by my employer that I can spend work hours implementing it.
Suggested solution
I propose to use an API such as the one shown above. Suggestions for alternative naming etc are more than welcome.
Alternative
I know of no good alternative. One could use Typescripts Decorators, but that would require adding in a decorator for every test.
Additional context
This has also been requested here:
#3232
Validations