Answer the question
In order to leave comments, you need to log in
How to lock a function that returns a Promise?
Hello.
Project on NestJS ( nestjs.com ). I want to write a test.
I have a controller:
@Get()
async findAll(@Res() res): Promise<any[]> {
return await this.service.getItems().then(result => res.json(result));
}
describe('findAll', () => {
it('should return an array of cats', async () => {
const result = ['test'];
jest.spyOn(catsService, 'getItems').mockImplementation(() => Promise.resolve(result));
expect(await catsController.findAll()).toBe(result);
});
});
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question