MCPcopy
hub / github.com/vitest-dev/vitest / afterEach

Function afterEach

packages/runner/src/hooks.ts:201–221  ·  view source on GitHub ↗
(
  fn: AfterEachListener<ExtraContext>,
  timeout?: number,
)

Source from the content-addressed store, hash-verified

199 * ```
200 */
201export function afterEach<ExtraContext = object>(
202 fn: AfterEachListener<ExtraContext>,
203 timeout?: number,
204): void {
205 assertTypes(fn, '"afterEach" callback', ['function'])
206 const wrapper: AfterEachListener<ExtraContext> = (context, suite) => {
207 const fixtureResolver = withFixtures(fn, { suite })
208 return fixtureResolver(context)
209 }
210
211 return getCurrentSuite<ExtraContext>().on(
212 'afterEach',
213 withTimeout(
214 wrapper,
215 timeout ?? getDefaultHookTimeout(),
216 true,
217 new Error('STACK_TRACE_ERROR'),
218 abortIfTimeout,
219 ),
220 )
221}
222
223/**
224 * Registers a callback function to be executed when a test fails within the current suite.

Callers 15

utils.test.tsFile · 0.85
timers.test.tsFile · 0.85
server-url.test.tsFile · 0.85
basic.test.tsFile · 0.85
query.test.tsFile · 0.85
timeout.test.tsFile · 0.85
runVitestFunction · 0.85

Calls 5

assertTypesFunction · 0.90
getCurrentSuiteFunction · 0.90
withTimeoutFunction · 0.90
getDefaultHookTimeoutFunction · 0.85
onMethod · 0.45

Tested by

no test coverage detected