File tree Expand file tree Collapse file tree 1 file changed +20
-0
lines changed
packages/jest-mock/src/__tests__ Expand file tree Collapse file tree 1 file changed +20
-0
lines changed Original file line number Diff line number Diff line change @@ -598,6 +598,26 @@ describe('moduleMocker', () => {
598598 expect ( fn2 ( ) ) . not . toBe ( 'abcd' ) ;
599599 } ) ;
600600
601+ it ( 'is not affected by restoreAllMocks' , ( ) => {
602+ const fn1 = moduleMocker . fn ( ) ;
603+ fn1 . mockImplementation ( ( ) => 'abcd' ) ;
604+ fn1 ( 1 , 2 , 3 ) ;
605+ expect ( fn1 . mock . calls ) . toEqual ( [ [ 1 , 2 , 3 ] ] ) ;
606+ moduleMocker . restoreAllMocks ( ) ;
607+ expect ( fn1 ( 1 ) ) . toBe ( 'abcd' ) ;
608+ expect ( fn1 . mock . calls ) . toEqual ( [ [ 1 , 2 , 3 ] , [ 1 ] ] ) ;
609+ } ) ;
610+
611+ it ( 'is cleared and stubbed when restored explicitly' , ( ) => {
612+ const fn1 = moduleMocker . fn ( ) ;
613+ fn1 . mockImplementation ( ( ) => 'abcd' ) ;
614+ fn1 ( 1 , 2 , 3 ) ;
615+ expect ( fn1 . mock . calls ) . toEqual ( [ [ 1 , 2 , 3 ] ] ) ;
616+ fn1 . mockRestore ( ) ;
617+ expect ( fn1 ( 1 ) ) . toBeUndefined ( ) ;
618+ expect ( fn1 . mock . calls ) . toEqual ( [ [ 1 ] ] ) ;
619+ } ) ;
620+
601621 it ( 'maintains function arity' , ( ) => {
602622 const mockFunctionArity1 = moduleMocker . fn ( x => x ) ;
603623 const mockFunctionArity2 = moduleMocker . fn ( ( x , y ) => y ) ;
You can’t perform that action at this time.
0 commit comments