Hooks allow you to run setup and teardown logic before or after your tests or test suites.
(fn: (ctx: SuiteContext) => void | Promise<void>, timeout?: number) => void
Runs once before all tests in the current suite.
(fn: (ctx: SuiteContext) => void | Promise<void>, timeout?: number) => void
Runs once after all tests in the current suite.
(fn: () => void | Promise<void>, timeout?: number) => void
Runs before each test in the current suite.
(fn: () => void | Promise<void>, timeout?: number) => void
Runs after each test in the current suite.
(fn: () => void | Promise<void>, timeout?: number) => void
Called after the test has finished running whatever the test result is. This can be used to perform cleanup actions. This hook will be called after afterEach
.
It should be noted that when you use the onTestFinished
hook in concurrent tests, you should get the hook from the test context. This is because Rstest cannot accurately track the specific test to which the global onTestFinished
hook belongs in concurrent tests.