I’m trying to write a unit test for my API using Jest and I’m using some boilerplate code but it’s leading me to an error that I don’t understand. Here is the test:
describe('findAll', () => {
it('should return an array of cats', async () => {
const result = ['test'];
jest.spyOn(catsService, 'findAll').mockImplementation(() => result);
expect(await catsController.findAll()).toBe(result);
});
});
The error is in the part () => result:
Type ‘string[]’ is not assignable to type ‘Cat[]’
My findAll method within catsController is very straightforward, it just return an array of Cat objects:
findAll(): Cat[] {
return this.catsService.findAll();
}
What is incorrect about my mockImplementation?