我是 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)