@@ -634,6 +634,70 @@ describe('toHaveBeenCalledWith', () => {
634634 } )
635635} )
636636
637+ describe ( 'toHaveBeenCalledExactlyOnceWith' , ( ) => {
638+ describe ( 'negated' , ( ) => {
639+ it ( 'fails if called' , ( ) => {
640+ const mock = vi . fn ( )
641+ mock ( 3 )
642+
643+ expect ( ( ) => {
644+ expect ( mock ) . not . toHaveBeenCalledExactlyOnceWith ( 3 )
645+ } ) . toThrow ( / ^ e x p e c t e d " s p y " t o n o t b e c a l l e d o n c e w i t h a r g u m e n t s : \[ 3 \] [ ^ e ] / )
646+ } )
647+
648+ it ( 'passes if called multiple times with args' , ( ) => {
649+ const mock = vi . fn ( )
650+ mock ( 3 )
651+ mock ( 3 )
652+
653+ expect ( mock ) . not . toHaveBeenCalledExactlyOnceWith ( 3 )
654+ } )
655+
656+ it ( 'passes if not called' , ( ) => {
657+ const mock = vi . fn ( )
658+ expect ( mock ) . not . toHaveBeenCalledExactlyOnceWith ( 3 )
659+ } )
660+
661+ it ( 'passes if called with a different argument' , ( ) => {
662+ const mock = vi . fn ( )
663+ mock ( 4 )
664+
665+ expect ( mock ) . not . toHaveBeenCalledExactlyOnceWith ( 3 )
666+ } )
667+ } )
668+
669+ it ( 'fails if not called or called too many times' , ( ) => {
670+ const mock = vi . fn ( )
671+
672+ expect ( ( ) => {
673+ expect ( mock ) . toHaveBeenCalledExactlyOnceWith ( 3 )
674+ } ) . toThrow ( / ^ e x p e c t e d " s p y " t o b e c a l l e d o n c e w i t h a r g u m e n t s : \[ 3 \] [ ^ e ] / )
675+
676+ mock ( 3 )
677+ mock ( 3 )
678+
679+ expect ( ( ) => {
680+ expect ( mock ) . toHaveBeenCalledExactlyOnceWith ( 3 )
681+ } ) . toThrow ( / ^ e x p e c t e d " s p y " t o b e c a l l e d o n c e w i t h a r g u m e n t s : \[ 3 \] [ ^ e ] / )
682+ } )
683+
684+ it ( 'fails if called with wrong args' , ( ) => {
685+ const mock = vi . fn ( )
686+ mock ( 4 )
687+
688+ expect ( ( ) => {
689+ expect ( mock ) . toHaveBeenCalledExactlyOnceWith ( 3 )
690+ } ) . toThrow ( / ^ e x p e c t e d " s p y " t o b e c a l l e d o n c e w i t h a r g u m e n t s : \[ 3 \] [ ^ e ] / )
691+ } )
692+
693+ it ( 'passes if called exactly once with args' , ( ) => {
694+ const mock = vi . fn ( )
695+ mock ( 3 )
696+
697+ expect ( mock ) . toHaveBeenCalledExactlyOnceWith ( 3 )
698+ } )
699+ } )
700+
637701describe ( 'async expect' , ( ) => {
638702 it ( 'resolves' , async ( ) => {
639703 await expect ( ( async ( ) => 'true' ) ( ) ) . resolves . toBe ( 'true' )
0 commit comments