@@ -641,11 +641,9 @@ describe('browser', function() {
641641 } ) ;
642642
643643 describe ( 'url (when state passed)' , function ( ) {
644- var currentHref ;
644+ var currentHref , pushState , replaceState , locationReplace ;
645645
646646 beforeEach ( function ( ) {
647- sniffer = { history : true } ;
648- currentHref = fakeWindow . location . href ;
649647 } ) ;
650648
651649 describe ( 'in IE' , runTests ( { msie : true } ) ) ;
@@ -654,7 +652,14 @@ describe('browser', function() {
654652 function runTests ( options ) {
655653 return function ( ) {
656654 beforeEach ( function ( ) {
655+ sniffer = { history : true } ;
656+
657657 fakeWindow = new MockWindow ( { msie : options . msie } ) ;
658+ currentHref = fakeWindow . location . href ;
659+ pushState = spyOn ( fakeWindow . history , 'pushState' ) . andCallThrough ( ) ;
660+ replaceState = spyOn ( fakeWindow . history , 'replaceState' ) . andCallThrough ( ) ;
661+ locationReplace = spyOn ( fakeWindow . location , 'replace' ) . andCallThrough ( ) ;
662+
658663 browser = new Browser ( fakeWindow , fakeDocument , fakeLog , sniffer ) ;
659664 browser . onUrlChange ( function ( ) { } ) ;
660665 } ) ;
@@ -703,20 +708,27 @@ describe('browser', function() {
703708 expect ( fakeWindow . history . state ) . toEqual ( { prop : 'val3' } ) ;
704709 } ) ;
705710
706- it ( 'should do pushState with the same URL and null state' , function ( ) {
707- fakeWindow . history . state = { prop : 'val1 ' } ;
711+ it ( 'should do pushState with the same URL and deep equal but referentially different state' , function ( ) {
712+ fakeWindow . history . state = { prop : 'val ' } ;
708713 fakeWindow . fire ( 'popstate' ) ;
714+ expect ( historyEntriesLength ) . toBe ( 1 ) ;
709715
710- browser . url ( currentHref , false , null ) ;
711- expect ( fakeWindow . history . state ) . toEqual ( null ) ;
716+ browser . url ( currentHref , false , { prop : 'val' } ) ;
717+ expect ( fakeWindow . history . state ) . toEqual ( { prop : 'val' } ) ;
718+ expect ( historyEntriesLength ) . toBe ( 2 ) ;
712719 } ) ;
713720
714- it ( 'should do pushState with the same URL and the same non-null state' , function ( ) {
715- fakeWindow . history . state = null ;
716- fakeWindow . fire ( 'popstate' ) ;
721+ it ( 'should not do pushState with the same URL and state from $browser.state()' , function ( ) {
722+ browser . url ( currentHref , false , { prop : 'val' } ) ;
717723
718- browser . url ( currentHref , false , { prop : 'val2' } ) ;
719- expect ( fakeWindow . history . state ) . toEqual ( { prop : 'val2' } ) ;
724+ pushState . reset ( ) ;
725+ replaceState . reset ( ) ;
726+ locationReplace . reset ( ) ;
727+
728+ browser . url ( currentHref , false , browser . state ( ) ) ;
729+ expect ( pushState ) . not . toHaveBeenCalled ( ) ;
730+ expect ( replaceState ) . not . toHaveBeenCalled ( ) ;
731+ expect ( locationReplace ) . not . toHaveBeenCalled ( ) ;
720732 } ) ;
721733 } ;
722734 }
0 commit comments