@@ -11,8 +11,9 @@ function MockWindow(options) {
11
11
}
12
12
var events = { } ;
13
13
var timeouts = this . timeouts = [ ] ;
14
- var locationHref = 'http://server/' ;
15
- var committedHref = 'http://server/' ;
14
+ var locationHref = document . createElement ( 'a' ) ;
15
+ var committedHref = document . createElement ( 'a' ) ;
16
+ locationHref . href = committedHref . href = 'http://server/' ;
16
17
var mockWindow = this ;
17
18
var msie = options . msie ;
18
19
var ieState ;
@@ -60,28 +61,28 @@ function MockWindow(options) {
60
61
61
62
this . location = {
62
63
get href ( ) {
63
- return committedHref ;
64
+ return committedHref . href ;
64
65
} ,
65
66
set href ( value ) {
66
- locationHref = value ;
67
+ locationHref . href = value ;
67
68
mockWindow . history . state = null ;
68
69
historyEntriesLength ++ ;
69
70
if ( ! options . updateAsync ) this . flushHref ( ) ;
70
71
} ,
71
72
get hash ( ) {
72
- return getHash ( committedHref ) ;
73
+ return getHash ( committedHref . href ) ;
73
74
} ,
74
75
set hash ( value ) {
75
- locationHref = replaceHash ( locationHref , value ) ;
76
+ locationHref . href = replaceHash ( locationHref . href , value ) ;
76
77
if ( ! options . updateAsync ) this . flushHref ( ) ;
77
78
} ,
78
79
replace : function ( url ) {
79
- locationHref = url ;
80
+ locationHref . href = url ;
80
81
mockWindow . history . state = null ;
81
82
if ( ! options . updateAsync ) this . flushHref ( ) ;
82
83
} ,
83
84
flushHref : function ( ) {
84
- committedHref = locationHref ;
85
+ committedHref . href = locationHref . href ;
85
86
}
86
87
} ;
87
88
@@ -91,13 +92,13 @@ function MockWindow(options) {
91
92
historyEntriesLength ++ ;
92
93
} ,
93
94
replaceState : function ( state , title , url ) {
94
- locationHref = url ;
95
- if ( ! options . updateAsync ) committedHref = locationHref ;
95
+ locationHref . href = url ;
96
+ if ( ! options . updateAsync ) committedHref . href = locationHref . href ;
96
97
mockWindow . history . state = copy ( state ) ;
97
98
if ( ! options . updateAsync ) this . flushHref ( ) ;
98
99
} ,
99
100
flushHref : function ( ) {
100
- committedHref = locationHref ;
101
+ committedHref . href = locationHref . href ;
101
102
}
102
103
} ;
103
104
// IE 10-11 deserialize history.state on each read making subsequent reads
@@ -285,10 +286,10 @@ describe('browser', function() {
285
286
286
287
it ( 'should return current location.href' , function ( ) {
287
288
fakeWindow . location . href = 'http://test.com' ;
288
- expect ( browser . url ( ) ) . toEqual ( 'http://test.com' ) ;
289
+ expect ( browser . url ( ) ) . toEqual ( 'http://test.com/ ' ) ;
289
290
290
291
fakeWindow . location . href = 'https://another.com' ;
291
- expect ( browser . url ( ) ) . toEqual ( 'https://another.com' ) ;
292
+ expect ( browser . url ( ) ) . toEqual ( 'https://another.com/ ' ) ;
292
293
} ) ;
293
294
294
295
it ( 'should use history.pushState when available' , function ( ) {
@@ -319,7 +320,7 @@ describe('browser', function() {
319
320
sniffer . history = false ;
320
321
browser . url ( 'http://new.org' ) ;
321
322
322
- expect ( fakeWindow . location . href ) . toEqual ( 'http://new.org' ) ;
323
+ expect ( fakeWindow . location . href ) . toEqual ( 'http://new.org/ ' ) ;
323
324
324
325
expect ( pushState ) . not . toHaveBeenCalled ( ) ;
325
326
expect ( replaceState ) . not . toHaveBeenCalled ( ) ;
@@ -386,9 +387,9 @@ describe('browser', function() {
386
387
it ( 'should not set URL when the URL is already set' , function ( ) {
387
388
var current = fakeWindow . location . href ;
388
389
sniffer . history = false ;
389
- fakeWindow . location . href = 'dontchange' ;
390
+ fakeWindow . location . href = 'http:// dontchange/ ' ;
390
391
browser . url ( current ) ;
391
- expect ( fakeWindow . location . href ) . toBe ( 'dontchange' ) ;
392
+ expect ( fakeWindow . location . href ) . toBe ( 'http:// dontchange/ ' ) ;
392
393
} ) ;
393
394
394
395
it ( 'should not read out location.href if a reload was triggered but still allow to change the url' , function ( ) {
@@ -691,7 +692,7 @@ describe('browser', function() {
691
692
it ( 'should not fire urlChange if changed by browser.url method' , function ( ) {
692
693
sniffer . history = false ;
693
694
browser . onUrlChange ( callback ) ;
694
- browser . url ( 'http://new.com' ) ;
695
+ browser . url ( 'http://new.com/ ' ) ;
695
696
696
697
fakeWindow . fire ( 'hashchange' ) ;
697
698
expect ( callback ) . not . toHaveBeenCalled ( ) ;
0 commit comments