|
1 | 1 | 'use strict';
|
2 | 2 |
|
3 | 3 | /* global getHash:true, stripHash:true */
|
| 4 | +/* jshint evil:true */ |
4 | 5 |
|
5 | 6 | var historyEntriesLength;
|
6 | 7 | var sniffer = {};
|
@@ -45,26 +46,37 @@ function MockWindow(options) {
|
45 | 46 | });
|
46 | 47 | };
|
47 | 48 |
|
48 |
| - this.location = { |
49 |
| - get href() { |
50 |
| - return locationHref; |
51 |
| - }, |
52 |
| - set href(value) { |
| 49 | + //IE8 hack. defineProperty doesn't work with POJS, just with certain DOM elements |
| 50 | + this.location = document.createElement('div'); |
| 51 | + this.location.href = {}; |
| 52 | + this.location.hash = {}; |
| 53 | + this.location.replace = function(url) { |
| 54 | + locationHref = url; |
| 55 | + mockWindow.history.state = null; |
| 56 | + }; |
| 57 | + Object.defineProperty(this.location, 'href', { |
| 58 | + enumerable: false, |
| 59 | + configurable: true, |
| 60 | + set: function(value) { |
53 | 61 | locationHref = value;
|
54 | 62 | mockWindow.history.state = null;
|
55 | 63 | historyEntriesLength++;
|
56 | 64 | },
|
57 |
| - get hash() { |
58 |
| - return getHash(locationHref); |
59 |
| - }, |
60 |
| - set hash(value) { |
| 65 | + get: function() { |
| 66 | + return locationHref; |
| 67 | + } |
| 68 | + }); |
| 69 | + |
| 70 | + Object.defineProperty(this.location, 'hash', { |
| 71 | + enumerable: false, |
| 72 | + configurable: true, |
| 73 | + set: function(value) { |
61 | 74 | locationHref = stripHash(locationHref) + '#' + value;
|
62 | 75 | },
|
63 |
| - replace: function(url) { |
64 |
| - locationHref = url; |
65 |
| - mockWindow.history.state = null; |
| 76 | + get: function() { |
| 77 | + return getHash(locationHref); |
66 | 78 | }
|
67 |
| - }; |
| 79 | + }); |
68 | 80 |
|
69 | 81 | this.history = {
|
70 | 82 | replaceState: noop,
|
@@ -115,7 +127,6 @@ describe('browser', function() {
|
115 | 127 | warn: function() { logs.warn.push(slice.call(arguments)); },
|
116 | 128 | info: function() { logs.info.push(slice.call(arguments)); },
|
117 | 129 | error: function() { logs.error.push(slice.call(arguments)); }};
|
118 |
| - |
119 | 130 | browser = new Browser(fakeWindow, fakeDocument, fakeLog, sniffer);
|
120 | 131 | });
|
121 | 132 |
|
|
0 commit comments