Skip to content

Commit 35341b8

Browse files
committed
Fix the tag.controller test
- provide more detailed TS mock implementation
1 parent e392d13 commit 35341b8

File tree

1 file changed

+13
-3
lines changed

1 file changed

+13
-3
lines changed

src/tag/tag.controller.spec.ts

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,20 @@ describe('TagController', () => {
2121

2222
describe('findAll', () => {
2323
it('should return an array of tags', async () => {
24-
const result = ['angularjs', 'reactjs'];
25-
jest.spyOn(tagService, 'findAll').mockImplementation(() => result);
24+
const tags : TagEntity[] = [];
25+
const createTag = (id, name) => {
26+
const tag = new TagEntity();
27+
tag.id = id;
28+
tag.tag = name;
29+
return tag;
30+
}
31+
tags.push(createTag(1, 'angularjs'));
32+
tags.push(createTag(2, 'reactjs'));
2633

27-
expect(await tagController.findAll()).toBe(result);
34+
jest.spyOn(tagService, 'findAll').mockImplementation(() => Promise.resolve(tags));
35+
36+
const findAllResult = await tagController.findAll();
37+
expect(findAllResult).toBe(tags);
2838
});
2939
});
3040
});

0 commit comments

Comments
 (0)