@@ -62,11 +62,11 @@ class WhenMock {
6262 fn . __whenMock__ = this
6363 this . callMocks = [ ]
6464 this . _origMock = fn . getMockImplementation ( )
65- this . defaultImplementation = null
65+ this . _defaultImplementation = null
6666
6767 const _mockImplementation = ( matchers , expectCall , once = false ) => ( mockImplementation ) => {
6868 if ( matchers [ 0 ] === NO_CALLED_WITH_YET ) {
69- this . defaultImplementation = mockImplementation
69+ this . _defaultImplementation = mockImplementation
7070 }
7171 // To enable dynamic replacement during a test:
7272 // * call mocks with equal matchers are removed
@@ -108,8 +108,8 @@ class WhenMock {
108108 }
109109 }
110110
111- if ( this . defaultImplementation ) {
112- return this . defaultImplementation ( ...args )
111+ if ( this . _defaultImplementation ) {
112+ return this . _defaultImplementation ( ...args )
113113 }
114114 if ( typeof fn . __whenMock__ . _origMock === 'function' ) {
115115 return fn . __whenMock__ . _origMock ( ...args )
@@ -131,18 +131,26 @@ class WhenMock {
131131 mockRejectedValue : err => _mockImplementation ( matchers , expectCall ) ( ( ) => Promise . reject ( err ) ) ,
132132 mockRejectedValueOnce : err => _mockImplementation ( matchers , expectCall , true ) ( ( ) => Promise . reject ( err ) ) ,
133133 mockImplementation : implementation => _mockImplementation ( matchers , expectCall ) ( implementation ) ,
134- mockImplementationOnce : implementation => _mockImplementation ( matchers , expectCall , true ) ( implementation )
134+ mockImplementationOnce : implementation => _mockImplementation ( matchers , expectCall , true ) ( implementation ) ,
135+ defaultImplementation : implementation => this . defaultImplementation ( implementation ) ,
136+ defaultReturnValue : returnValue => this . defaultReturnValue ( returnValue ) ,
137+ defaultResolvedValue : returnValue => this . defaultResolvedValue ( returnValue ) ,
138+ defaultRejectedValue : err => this . defaultRejectedValue ( err )
135139 } )
136140
137141 // These four functions are only used when the dev has not used `.calledWith` before calling one of the mock return functions
138- this . mockImplementation = mockImplementation => {
142+ this . defaultImplementation = mockImplementation => {
139143 // Set up an implementation with a special matcher that can never be matched because it uses a private symbol
140144 // Additionally the symbols existence can be checked to see if a calledWith was omitted.
141145 return _mockImplementation ( [ NO_CALLED_WITH_YET ] , false ) ( mockImplementation )
142146 }
143- this . mockReturnValue = returnValue => this . mockImplementation ( ( ) => returnValue )
144- this . mockResolvedValue = returnValue => this . mockReturnValue ( Promise . resolve ( returnValue ) )
145- this . mockRejectedValue = err => this . mockReturnValue ( Promise . reject ( err ) )
147+ this . defaultReturnValue = returnValue => this . defaultImplementation ( ( ) => returnValue )
148+ this . defaultResolvedValue = returnValue => this . defaultReturnValue ( Promise . resolve ( returnValue ) )
149+ this . defaultRejectedValue = err => this . defaultResolvedValue ( Promise . reject ( err ) )
150+ this . mockImplementation = this . defaultImplementation
151+ this . mockReturnValue = this . defaultReturnValue
152+ this . mockResolvedValue = this . defaultResolvedValue
153+ this . mockRejectedValue = this . defaultRejectedValue
146154
147155 this . calledWith = ( ...matchers ) => ( { ...mockFunctions ( matchers , false ) } )
148156 this . expectCalledWith = ( ...matchers ) => ( { ...mockFunctions ( matchers , true ) } )
0 commit comments