context.after([fn][, options])


  • fn <Function> | <AsyncFunction> 钩子函数。 此函数的第一个参数是 TestContext 对象。 如果钩子使用回调,则回调函数作为第二个参数传入。 默认值: 无操作的函数。
  • options <Object> 钩子的配置选项。 支持以下属性:
    • signal <AbortSignal> 允许中止正在进行的钩子。
    • timeout <number> 钩子会在几毫秒后失败。 如果未指定,则子测试从其父测试继承此值。 默认值: Infinity

此函数用于创建一个在当前测试完成后运行的钩子。

test('top level test', async (t) => {
  t.after((t) => t.diagnostic(`finished running ${t.name}`));
  assert.ok('some relevant assertion here');
});
  • fn <Function> | <AsyncFunction> The hook function. The first argument to this function is a TestContext object. If the hook uses callbacks, the callback function is passed as the second argument. Default: A no-op function.
  • options <Object> Configuration options for the hook. The following properties are supported:
    • signal <AbortSignal> Allows aborting an in-progress hook.
    • timeout <number> A number of milliseconds the hook will fail after. If unspecified, subtests inherit this value from their parent. Default: Infinity.

This function is used to create a hook that runs after the current test finishes.

test('top level test', async (t) => {
  t.after((t) => t.diagnostic(`finished running ${t.name}`));
  assert.ok('some relevant assertion here');
});