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


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

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

【This function is used to create a hook running before subtest of the current test.】