File tree Expand file tree Collapse file tree 2 files changed +31
-3
lines changed Expand file tree Collapse file tree 2 files changed +31
-3
lines changed Original file line number Diff line number Diff line change 11import { IndexController } from '../../src/controllers/IndexController' ;
2- import { Request , Response } from 'express' ;
2+ import { NextFunction , Request , Response } from 'express' ;
33
44describe ( 'IndexController' , ( ) => {
55 it ( 'should respond as expected' , ( ) => {
66 const request = { } ;
77 const response = {
88 json : jest . fn ( ) ,
99 } ;
10+ const next : NextFunction = jest . fn ( ) ;
1011
11- IndexController ( request as Request , response as unknown as Response ) ;
12+ IndexController ( request as Request , response as unknown as Response , next ) ;
1213
13- expect ( response . json ) . toBeCalledWith ( [ 'ok' ] ) ;
14+ expect ( response . json ) . toBeCalledWith (
15+ expect . objectContaining ( {
16+ status : 200 ,
17+ } ) ,
18+ ) ;
1419 } ) ;
1520} ) ;
Original file line number Diff line number Diff line change 11import { AppDataSource , initialiseDataSource , destroyDataSource } from '../../src/database' ;
22
33describe ( 'DataSource Utility' , ( ) => {
4+ let initCount : number = 0 ;
45 const originalConsoleError = console . error ;
56
67 beforeEach ( async ( ) => {
78 console . error = jest . fn ( ) ;
89
10+ jest . spyOn ( AppDataSource , 'initialize' ) . mockImplementation ( async ( ) => {
11+ initCount ++ ;
12+ if ( initCount > 1 ) {
13+ throw new Error ( 'initialize called more than once before destroying.' ) ;
14+ }
15+ Object . defineProperty ( AppDataSource , 'isInitialized' , {
16+ value : true ,
17+ writable : true ,
18+ configurable : true ,
19+ } ) ;
20+ return AppDataSource ;
21+ } ) ;
22+
23+ jest . spyOn ( AppDataSource , 'destroy' ) . mockImplementation ( async ( ) => {
24+ initCount = 0 ;
25+ Object . defineProperty ( AppDataSource , 'isInitialized' , {
26+ value : false ,
27+ writable : true ,
28+ configurable : true ,
29+ } ) ;
30+ } ) ;
31+
932 if ( ! AppDataSource . isInitialized ) {
1033 await initialiseDataSource ( ) ;
1134 }
You can’t perform that action at this time.
0 commit comments