( fn: BeforeEachListener<ExtraContext>, timeout: number = getDefaultHookTimeout(), )
| 152 | * ``` |
| 153 | */ |
| 154 | export function beforeEach<ExtraContext = object>( |
| 155 | fn: BeforeEachListener<ExtraContext>, |
| 156 | timeout: number = getDefaultHookTimeout(), |
| 157 | ): void { |
| 158 | assertTypes(fn, '"beforeEach" callback', ['function']) |
| 159 | const stackTraceError = new Error('STACK_TRACE_ERROR') |
| 160 | |
| 161 | const wrapper: BeforeEachListener<ExtraContext> = (context, suite) => { |
| 162 | const fixtureResolver = withFixtures(fn, { suite }) |
| 163 | return fixtureResolver(context) |
| 164 | } |
| 165 | |
| 166 | return getCurrentSuite<ExtraContext>().on( |
| 167 | 'beforeEach', |
| 168 | Object.assign( |
| 169 | withTimeout( |
| 170 | wrapper, |
| 171 | timeout ?? getDefaultHookTimeout(), |
| 172 | true, |
| 173 | stackTraceError, |
| 174 | abortIfTimeout, |
| 175 | ), |
| 176 | { |
| 177 | [CLEANUP_TIMEOUT_KEY]: timeout, |
| 178 | [CLEANUP_STACK_TRACE_KEY]: stackTraceError, |
| 179 | }, |
| 180 | ), |
| 181 | ) |
| 182 | } |
| 183 | |
| 184 | /** |
| 185 | * Registers a callback function to be executed after each test within the current suite has completed. |
no test coverage detected