如何将未定义的值传递给 jest.expect?

How to pass an undefined value to jest.expect?

我正在 strictNullChecks.
编写 TS 项目 我想确保函数的结果是未定义的:

const company = await getRepository(Company).findOne({ id: deletedID });
expect(company).toBeUndefined();
       ^^^^^^^ 

但是,ESLint 在预期行上给我这个警告:Passing nullable argument to function that expects non nullable

我也可以 expect(company === undefined).toBe(true) 但有没有办法使用 .toBeUndefined()

您可以这样使用 as

expect(company as any).toBeUndefined();