@@ -841,6 +841,109 @@ describe("assert", function () {
841841 } ) ;
842842 } ) ;
843843
844+ describe ( ".calledOnceWith" , function ( ) {
845+ // eslint-disable-next-line mocha/no-setup-in-describe
846+ requiresValidFake ( "calledOnceWith" ) ;
847+
848+ it ( "fails when method fails" , function ( ) {
849+ const object = { } ;
850+ sinonStub ( this . stub , "calledOnceWith" ) . returns ( false ) ;
851+ const stub = this . stub ;
852+
853+ assert . exception ( function ( ) {
854+ sinonAssert . calledOnceWith ( stub , object , 1 ) ;
855+ } ) ;
856+
857+ assert (
858+ this . stub . calledOnceWith . calledOnceWithExactly ( object , 1 ) ,
859+ ) ;
860+ assert ( sinonAssert . fail . called ) ;
861+ } ) ;
862+
863+ it ( "passes when method doesn't fail" , function ( ) {
864+ const object = { } ;
865+ sinonStub ( this . stub , "calledOnceWith" ) . returns ( true ) ;
866+ const stub = this . stub ;
867+
868+ refute . exception ( function ( ) {
869+ sinonAssert . calledOnceWith ( stub , object , 1 ) ;
870+ } ) ;
871+
872+ assert (
873+ this . stub . calledOnceWith . calledOnceWithExactly ( object , 1 ) ,
874+ ) ;
875+ assert . isFalse ( sinonAssert . fail . called ) ;
876+ } ) ;
877+
878+ it ( "calls pass callback" , function ( ) {
879+ this . stub ( "yeah" ) ;
880+ sinonAssert . calledOnceWith ( this . stub , "yeah" ) ;
881+
882+ assert ( sinonAssert . pass . calledOnce ) ;
883+ assert ( sinonAssert . pass . calledWith ( "calledOnceWith" ) ) ;
884+ } ) ;
885+
886+ it ( "fails when method does not exist" , function ( ) {
887+ assert . exception ( function ( ) {
888+ sinonAssert . calledOnceWith ( ) ;
889+ } ) ;
890+
891+ assert ( sinonAssert . fail . called ) ;
892+ } ) ;
893+
894+ it ( "fails when method is not stub" , function ( ) {
895+ assert . exception ( function ( ) {
896+ sinonAssert . calledOnceWith ( function ( ) {
897+ return ;
898+ } ) ;
899+ } ) ;
900+
901+ assert ( sinonAssert . fail . called ) ;
902+ } ) ;
903+
904+ it ( "fails when method was not called" , function ( ) {
905+ const stub = this . stub ;
906+
907+ assert . exception ( function ( ) {
908+ sinonAssert . calledOnceWith ( stub ) ;
909+ } ) ;
910+
911+ assert ( sinonAssert . fail . called ) ;
912+ } ) ;
913+
914+ it ( "fails when called with more than one argument" , function ( ) {
915+ const stub = this . stub ;
916+ stub ( ) ;
917+
918+ assert . exception ( function ( ) {
919+ sinonAssert . calledOnceWith ( stub , 1 ) ;
920+ } ) ;
921+ } ) ;
922+
923+ it ( "passes when method was called" , function ( ) {
924+ const stub = this . stub ;
925+ stub ( ) ;
926+
927+ refute . exception ( function ( ) {
928+ sinonAssert . calledOnceWith ( stub ) ;
929+ } ) ;
930+
931+ assert . isFalse ( sinonAssert . fail . called ) ;
932+ } ) ;
933+
934+ it ( "fails when method was called more than once" , function ( ) {
935+ const stub = this . stub ;
936+ stub ( ) ;
937+ stub ( ) ;
938+
939+ assert . exception ( function ( ) {
940+ sinonAssert . calledOnceWith ( stub ) ;
941+ } ) ;
942+
943+ assert ( sinonAssert . fail . called ) ;
944+ } ) ;
945+ } ) ;
946+
844947 describe ( ".calledOnceWithExactly" , function ( ) {
845948 // eslint-disable-next-line mocha/no-setup-in-describe
846949 requiresValidFake ( "calledOnceWithExactly" ) ;
0 commit comments