Loopback4 - 使用 `@loopback/testlab` 时如何增加测试用例的默认超时时间

问题描述 投票:0回答:1

我有一些 API 需要 2 秒以上的时间。当我执行这些 API 的测试用例时,我收到以下错误

Error: Timeout of 2000ms exceeded. For async tests and hooks, ensure "done()" is called; if returning a Promise, ensure it resolves. (xxxxx/dist/__tests__/acceptance/employee.controller.acceptance.js)
      at listOnTimeout (node:internal/timers:559:17)
      at processTimers (node:internal/timers:502:7)

我遵循了这些线程中的答案如何增加摩卡中单个测试用例的超时时间。 它帮助我增加一个测试用例的超时,如下所示。如何为一组测试用例或所有测试用例配置超时?

describe('EmployeeController', () => {

  let app: ExpressServer;
  let client: Client;

  afterEach(async() => {
    
    clearDatabase();
    await app.stop();
    
  });

  beforeEach(async() => {

    ({app, client} = await setupApplication());

  });



  it('Create an employee - Fresh User', async() => {

    const token = await generateUserToken(client, '[email protected]');
    const resL = await client.get('/api/auth/users/my-account')
    .set({Authorization: `Bearer ${token}`}).send()
      .expect(200);
    const permissions = {
      ...accouontingPermissions,
      ...systemPermissions
    };
    await client.post('/api/auth/employees')
    .set({Authorization: `Bearer ${token}`}).send({
      name: 'Emp One',
      email: '[email protected]',
      permissions,
      role: 'user',
    })
      .expect(200);
    
  }).timeout(5000);;

});
typescript unit-testing web-api-testing loopback4
1个回答
0
投票

您可以在 .mocharc.json 文件中添加以下内容

{ “递归”:正确, "require": "source-map-support/register", “超时”:5000 }

© www.soinside.com 2019 - 2024. All rights reserved.