File tree Expand file tree Collapse file tree 1 file changed +38
-0
lines changed Expand file tree Collapse file tree 1 file changed +38
-0
lines changed Original file line number Diff line number Diff line change 1+ const { handleError } = require ( './handleError' )
2+
3+ const mockResponse = ( ) => {
4+ const res = { }
5+ res . status = jest . fn ( ) . mockReturnValueOnce ( res )
6+ res . json = jest . fn ( ) . mockReturnValueOnce ( res )
7+ return res
8+ }
9+
10+ const err = {
11+ message : 'error' ,
12+ code : 123
13+ }
14+
15+ describe ( 'handleError()' , ( ) => {
16+ it ( 'should send the error object with the code and message provided and print the error code, message in development mode' , async ( ) => {
17+ process . env . NODE_ENV = 'development'
18+
19+ const res = mockResponse ( )
20+
21+ console . log = jest . fn ( )
22+
23+ await handleError ( res , err )
24+
25+ expect ( console . log ) . toHaveBeenCalledWith ( {
26+ code : 123 ,
27+ message : 'error'
28+ } )
29+
30+ expect ( res . status ) . toHaveBeenCalledWith ( 123 )
31+
32+ expect ( res . json ) . toHaveBeenCalledWith ( {
33+ errors : {
34+ msg : 'error'
35+ }
36+ } )
37+ } )
38+ } )
You can’t perform that action at this time.
0 commit comments