beforeEach([, fn][, options])


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

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

🌐 This function is used to create a hook running before each subtest of the current suite.

describe('tests', async () => {
  beforeEach(() => t.diagnostic('about to run a test'));
  it('is a subtest', () => {
    assert.ok('some relevant assertion here');
  });
});