Skip to content

Commit d51f886

Browse files
committed
Check whether URL class is present again
Jasmine had this check before. Then it was removed in v4.0.0, commit fe0a83b "Removed support for Internet Explorer". Unfortunately, GJS has no built-in `URL` too.
1 parent e3a1646 commit d51f886

6 files changed

Lines changed: 36 additions & 7 deletions

File tree

‎spec/core/baseSpec.js‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ describe('base helpers', function() {
6969

7070
describe('isURL', function() {
7171
it('returns true when the object is a URL', function() {
72+
specHelpers.requireUrls();
7273
expect(privateUnderTest.isURL(new URL('http://localhost/'))).toBe(true);
7374
});
7475

‎spec/core/matchers/matchersUtilSpec.js‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -662,6 +662,8 @@ describe('matchersUtil', function() {
662662
});
663663

664664
it('passes when comparing two identical URLs', function() {
665+
specHelpers.requireUrls();
666+
665667
const matchersUtil = new privateUnderTest.MatchersUtil();
666668

667669
expect(
@@ -673,6 +675,8 @@ describe('matchersUtil', function() {
673675
});
674676

675677
it('fails when comparing two different URLs', function() {
678+
specHelpers.requireUrls();
679+
676680
const matchersUtil = new privateUnderTest.MatchersUtil();
677681
const url1 = new URL('http://localhost/1');
678682

‎spec/helpers/checkForUrl.js‎

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
(function() {
2+
function hasUrlConstructor() {
3+
try {
4+
new URL('http://localhost/');
5+
return true;
6+
} catch {
7+
return false;
8+
}
9+
}
10+
11+
specHelpers.requireUrls = function() {
12+
if (!hasUrlConstructor()) {
13+
pending('Environment does not support URLs');
14+
}
15+
};
16+
})();

‎spec/support/jasmine-browser.js‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ module.exports = {
2121
'helpers/init.js',
2222
'helpers/generator.js',
2323
'helpers/BrowserFlags.js',
24+
'helpers/checkForUrl.js',
2425
'helpers/domHelpers.js',
2526
'helpers/integrationMatchers.js',
2627
'helpers/callerFilenameShim.js',

‎spec/support/jasmine.json‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
],
77
"helpers": [
88
"helpers/init.js",
9+
"helpers/checkForUrl.js",
910
"helpers/domHelpers.js",
1011
"helpers/integrationMatchers.js",
1112
"helpers/callerFilenameShim.js",

‎src/core/base.js‎

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -177,13 +177,19 @@ getJasmineRequireObj().base = function(j$, private$, jasmineGlobal) {
177177
);
178178
};
179179

180-
private$.isURL = function(obj) {
181-
return (
182-
obj !== null &&
183-
typeof obj !== 'undefined' &&
184-
obj.constructor === jasmineGlobal.URL
185-
);
186-
};
180+
if (typeof jasmineGlobal.URL !== 'undefined') {
181+
private$.isURL = function(obj) {
182+
return (
183+
obj !== null &&
184+
typeof obj !== 'undefined' &&
185+
obj.constructor === jasmineGlobal.URL
186+
);
187+
};
188+
} else {
189+
private$.isURL = function(obj) {
190+
return false;
191+
};
192+
}
187193

188194
private$.isIterable = function(value) {
189195
return value && !!value[Symbol.iterator];

0 commit comments

Comments
 (0)