@@ -522,6 +522,105 @@ describe("Messages", function () {
522522 } ) ;
523523 } ) ;
524524
525+ describe ( "diff support" , function ( ) {
526+ it ( "should add actual/expected and set enableDiff to true" , function ( ) {
527+ var spy = sinon . spy ( ) ;
528+ spy ( "foo1" ) ;
529+
530+ var err ;
531+
532+ try {
533+ expect ( spy ) . to . have . been . calledWith ( "bar" ) ;
534+ } catch ( e ) {
535+ err = e ;
536+ }
537+ expect ( err ) . ok ;
538+ expect ( err ) . to . ownProperty ( "showDiff" , true ) ;
539+ expect ( err ) . to . ownProperty ( "actual" ) . deep . eq ( [ "foo1" ] ) ;
540+ expect ( err ) . to . ownProperty ( "expected" ) . deep . eq ( [ "bar" ] ) ;
541+ } ) ;
542+
543+ it ( "should use lastCall args if exists" , function ( ) {
544+ var spy = sinon . spy ( ) ;
545+ spy ( "foo1" ) ;
546+ spy ( "foo2" ) ;
547+
548+ var err ;
549+
550+ try {
551+ expect ( spy ) . to . have . been . calledWith ( "bar" ) ;
552+ } catch ( e ) {
553+ err = e ;
554+ }
555+ expect ( err ) . ok ;
556+ expect ( err ) . to . ownProperty ( "showDiff" , true ) ;
557+ expect ( err ) . to . ownProperty ( "actual" ) . deep . eq ( [ "foo2" ] ) ;
558+ expect ( err ) . to . ownProperty ( "expected" ) . deep . eq ( [ "bar" ] ) ;
559+ } ) ;
560+
561+ it ( "should use args if no lastCall" , function ( ) {
562+ var spy = sinon . spy ( ) ;
563+ spy ( "foo1" ) ;
564+ spy ( "foo2" ) ;
565+
566+ var err ;
567+
568+ try {
569+ expect ( spy . firstCall ) . to . have . been . calledWith ( "bar" ) ;
570+ } catch ( e ) {
571+ err = e ;
572+ }
573+ expect ( err ) . ok ;
574+ expect ( err ) . to . ownProperty ( "showDiff" , true ) ;
575+ expect ( err ) . to . ownProperty ( "actual" ) . deep . eq ( [ "foo1" ] ) ;
576+ expect ( err ) . to . ownProperty ( "expected" ) . deep . eq ( [ "bar" ] ) ;
577+ } ) ;
578+
579+ it ( "should use undefined if no call" , function ( ) {
580+ var spy = sinon . spy ( ) ;
581+
582+ var err ;
583+
584+ try {
585+ expect ( spy ) . to . have . been . calledWith ( "bar" ) ;
586+ } catch ( e ) {
587+ err = e ;
588+ }
589+ expect ( err ) . ok ;
590+ expect ( err ) . to . ownProperty ( "showDiff" , true ) ;
591+ expect ( err ) . to . ownProperty ( "actual" ) . deep . eq ( undefined ) ;
592+ expect ( err ) . to . ownProperty ( "expected" ) . deep . eq ( [ "bar" ] ) ;
593+ } ) ;
594+
595+ it ( "should not add actual/expected and set enableDiff to true if passes" , function ( ) {
596+ var spy = sinon . spy ( ) ;
597+ spy ( "foo" , "bar" , "baz" ) ;
598+
599+ var err ;
600+
601+ try {
602+ spy . should . calledWithExactly ( "foo" , "bar" , "baz" ) ;
603+ } catch ( e ) {
604+ err = e ;
605+ }
606+ expect ( err ) . to . be . undefined ;
607+ } ) ;
608+
609+ it ( "should not add actual/expected and set enableDiff if not 'calledWith' matcher" , function ( ) {
610+ var spy = sinon . spy ( ) ;
611+ spy ( "foo" , "bar" , "baz" ) ;
612+
613+ var err ;
614+
615+ try {
616+ expect ( spy ) . to . have . been . calledTwice ( ) ;
617+ } catch ( e ) {
618+ err = e ;
619+ }
620+ expect ( err ) . ownProperty ( "showDiff" ) . eq ( false ) ;
621+ } ) ;
622+ } ) ;
623+
525624 describe ( "when used on a non-spy/non-call" , function ( ) {
526625 function notSpy ( ) {
527626 // Contents don't matter
0 commit comments