@@ -641,11 +641,9 @@ describe('browser', function() {
641
641
} ) ;
642
642
643
643
describe ( 'url (when state passed)' , function ( ) {
644
- var currentHref ;
644
+ var currentHref , pushState , replaceState , locationReplace ;
645
645
646
646
beforeEach ( function ( ) {
647
- sniffer = { history : true } ;
648
- currentHref = fakeWindow . location . href ;
649
647
} ) ;
650
648
651
649
describe ( 'in IE' , runTests ( { msie : true } ) ) ;
@@ -654,7 +652,14 @@ describe('browser', function() {
654
652
function runTests ( options ) {
655
653
return function ( ) {
656
654
beforeEach ( function ( ) {
655
+ sniffer = { history : true } ;
656
+
657
657
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
+
658
663
browser = new Browser ( fakeWindow , fakeDocument , fakeLog , sniffer ) ;
659
664
browser . onUrlChange ( function ( ) { } ) ;
660
665
} ) ;
@@ -703,20 +708,27 @@ describe('browser', function() {
703
708
expect ( fakeWindow . history . state ) . toEqual ( { prop : 'val3' } ) ;
704
709
} ) ;
705
710
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 ' } ;
708
713
fakeWindow . fire ( 'popstate' ) ;
714
+ expect ( historyEntriesLength ) . toBe ( 1 ) ;
709
715
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 ) ;
712
719
} ) ;
713
720
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' } ) ;
717
723
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 ( ) ;
720
732
} ) ;
721
733
} ;
722
734
}
0 commit comments