Skip to content
This repository was archived by the owner on Apr 12, 2024. It is now read-only.

test(browser): change mock location definition to use defineProperty #10497

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 24 additions & 14 deletions test/ng/browserSpecs.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,26 +44,37 @@ function MockWindow(options) {
});
};

this.location = {
get href() {
return locationHref;
},
set href(value) {
//IE8 hack. defineProperty doesn't work with POJS, just with certain DOM elements
this.location = document.createElement('div');
this.location.href = {};
this.location.hash = {};
this.location.replace = function(url) {
locationHref = url;
mockWindow.history.state = null;
};
Object.defineProperty(this.location, 'href', {
enumerable: false,
configurable: true,
set: function(value) {
locationHref = value;
mockWindow.history.state = null;
historyEntriesLength++;
},
get hash() {
return getHash(locationHref);
},
set hash(value) {
get: function() {
return locationHref;
}
});

Object.defineProperty(this.location, 'hash', {
enumerable: false,
configurable: true,
set: function(value) {
locationHref = stripHash(locationHref) + '#' + value;
},
replace: function(url) {
locationHref = url;
mockWindow.history.state = null;
get: function() {
return getHash(locationHref);
}
};
});

this.history = {
pushState: function() {
Expand Down Expand Up @@ -134,7 +145,6 @@ describe('browser', function() {
warn: function() { logs.warn.push(slice.call(arguments)); },
info: function() { logs.info.push(slice.call(arguments)); },
error: function() { logs.error.push(slice.call(arguments)); }};

browser = new Browser(fakeWindow, fakeDocument, fakeLog, sniffer);
});

Expand Down