File tree Expand file tree Collapse file tree 1 file changed +13
-3
lines changed Expand file tree Collapse file tree 1 file changed +13
-3
lines changed Original file line number Diff line number Diff line change @@ -21,10 +21,20 @@ describe('TagController', () => {
21
21
22
22
describe ( 'findAll' , ( ) => {
23
23
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' ) ) ;
26
33
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 ) ;
28
38
} ) ;
29
39
} ) ;
30
40
} ) ;
You can’t perform that action at this time.
0 commit comments