小编jac*_*lsi的帖子

[]' 缺少类型 'Promise<Cats[]>' 中的以下属性:然后,catch,[Symbol.toStringTag],最后 ts(2739)

我是 typescript 和 nestjs 的新手,我正在尝试学习 nest js,但是当我尝试对我的代码进行单元测试时,结果变量给了我标题中显示的错误?任何人都可以帮助我尝试找出我在这里做错了什么。

describe('cats', () => {
  let controller: CatsController;
  let service: CatsService;
  beforeEach(async () => {
    const module: TestingModule = await Test.createTestingModule({
      controllers: [DeliveryController],
    }).compile();

    controller = module.get<CatsController>(CatsController);
  });
describe('', () => {
  it('should return an array of cats', async () => {
    const result = [
{
id: "1",
name: "Cat",
type: "hybrid"
}
          ];
    jest.spyOn(service, 'getCats').mockImplementation(() => result); //'result' in this line shows error

    expect(await controller.getAllCats()).toBe(result);
  });
})
});
Run Code Online (Sandbox Code Playgroud)

typescript jestjs nestjs

3
推荐指数
1
解决办法
5863
查看次数

标签 统计

jestjs ×1

nestjs ×1

typescript ×1