lujakob/nestjs-realworld-example-app

The 'tag.controller.spec.ts' fails – possible problem and fix

arbassic opened this issue · 0 comments

Hi there!

The example is just awesome, however when I run the test in my environment, an error occurs like in the screen below.

Test filed


I found the code below fixes that problem.

describe('findAll', () => {
it('should return an array of tags', async () => {
const tags : TagEntity[] = [];
const createTag = (id, name) => {
const tag = new TagEntity();
tag.id = id;
tag.tag = name;
return tag;
}
tags.push(createTag(1, 'angularjs'));
tags.push(createTag(2, 'reactjs'));
jest.spyOn(tagService, 'findAll').mockImplementation(() => Promise.resolve(tags));

const findAllResult = await tagController.findAll();
expect(findAllResult).toBe(tags);
});
});


Is there any other solution to the issue I met, to make the test work properly, better than providing the quite complex mock implementation?