@@ -329,6 +329,15 @@ getJasmineRequireObj().base = function(j$, jasmineGlobal) {
|
|||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
j$.isURL = function(obj) {
|
||||||
|
return (
|
||||||
|
obj !== null &&
|
||||||
|
typeof obj !== 'undefined' &&
|
||||||
|
typeof jasmineGlobal.URL !== 'undefined' &&
|
||||||
|
obj.constructor === jasmineGlobal.URL
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
j$.isDataView = function(obj) {
|
j$.isDataView = function(obj) {
|
||||||
return (
|
return (
|
||||||
obj !== null &&
|
obj !== null &&
|
||||||
@@ -5094,6 +5103,10 @@ getJasmineRequireObj().MatchersUtil = function(j$) {
|
|||||||
diffBuilder.recordMismatch();
|
diffBuilder.recordMismatch();
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
} else if (j$.isURL(a) && j$.isURL(b)) {
|
||||||
|
// URLs have no enumrable properties, so the default object comparison
|
||||||
|
// would consider any two URLs to be equal.
|
||||||
|
return a.toString() === b.toString();
|
||||||
} else {
|
} else {
|
||||||
// Objects with different constructors are not equivalent, but `Object`s
|
// Objects with different constructors are not equivalent, but `Object`s
|
||||||
// or `Array`s from different frames are.
|
// or `Array`s from different frames are.
|
||||||
|
|||||||
@@ -62,4 +62,17 @@ describe('base helpers', function() {
|
|||||||
expect(jasmineUnderTest.isSet({})).toBe(false);
|
expect(jasmineUnderTest.isSet({})).toBe(false);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe('isURL', function() {
|
||||||
|
it('returns true when the object is a URL', function() {
|
||||||
|
jasmine.getEnv().requireUrls();
|
||||||
|
// eslint-disable-next-line compat/compat
|
||||||
|
expect(jasmineUnderTest.isURL(new URL('http://localhost/'))).toBe(true);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('returns false when the object is not a URL', function() {
|
||||||
|
jasmine.getEnv().requireUrls();
|
||||||
|
expect(jasmineUnderTest.isURL({})).toBe(false);
|
||||||
|
});
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -837,6 +837,54 @@ describe('matchersUtil', function() {
|
|||||||
expect(matchersUtil.equals(mapA, mapB)).toBe(false);
|
expect(matchersUtil.equals(mapA, mapB)).toBe(false);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('passes when comparing two identical URLs', function() {
|
||||||
|
jasmine.getEnv().requireUrls();
|
||||||
|
|
||||||
|
var matchersUtil = new jasmineUnderTest.MatchersUtil();
|
||||||
|
|
||||||
|
expect(
|
||||||
|
matchersUtil.equals(
|
||||||
|
// eslint-disable-next-line compat/compat
|
||||||
|
new URL('http://localhost/1'),
|
||||||
|
// eslint-disable-next-line compat/compat
|
||||||
|
new URL('http://localhost/1')
|
||||||
|
)
|
||||||
|
).toBe(true);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('fails when comparing two different URLs', function() {
|
||||||
|
jasmine.getEnv().requireUrls();
|
||||||
|
|
||||||
|
var matchersUtil = new jasmineUnderTest.MatchersUtil(),
|
||||||
|
// eslint-disable-next-line compat/compat
|
||||||
|
url1 = new URL('http://localhost/1');
|
||||||
|
|
||||||
|
// eslint-disable-next-line compat/compat
|
||||||
|
expect(matchersUtil.equals(url1, new URL('http://localhost/2'))).toBe(
|
||||||
|
false
|
||||||
|
);
|
||||||
|
// eslint-disable-next-line compat/compat
|
||||||
|
expect(matchersUtil.equals(url1, new URL('http://localhost/1?foo'))).toBe(
|
||||||
|
false
|
||||||
|
);
|
||||||
|
// eslint-disable-next-line compat/compat
|
||||||
|
expect(matchersUtil.equals(url1, new URL('http://localhost/1#foo'))).toBe(
|
||||||
|
false
|
||||||
|
);
|
||||||
|
// eslint-disable-next-line compat/compat
|
||||||
|
expect(matchersUtil.equals(url1, new URL('https://localhost/1'))).toBe(
|
||||||
|
false
|
||||||
|
);
|
||||||
|
expect(
|
||||||
|
// eslint-disable-next-line compat/compat
|
||||||
|
matchersUtil.equals(url1, new URL('http://localhost:8080/1'))
|
||||||
|
).toBe(false);
|
||||||
|
// eslint-disable-next-line compat/compat
|
||||||
|
expect(matchersUtil.equals(url1, new URL('http://example.com/1'))).toBe(
|
||||||
|
false
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
describe('when running in an environment with array polyfills', function() {
|
describe('when running in an environment with array polyfills', function() {
|
||||||
var findIndexDescriptor = Object.getOwnPropertyDescriptor(
|
var findIndexDescriptor = Object.getOwnPropertyDescriptor(
|
||||||
Array.prototype,
|
Array.prototype,
|
||||||
|
|||||||
17
spec/helpers/checkForUrl.js
Normal file
17
spec/helpers/checkForUrl.js
Normal file
@@ -0,0 +1,17 @@
|
|||||||
|
/* eslint-disable compat/compat */
|
||||||
|
(function(env) {
|
||||||
|
function hasUrlConstructor() {
|
||||||
|
try {
|
||||||
|
new URL('http://localhost/');
|
||||||
|
return true;
|
||||||
|
} catch (e) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
env.requireUrls = function() {
|
||||||
|
if (!hasUrlConstructor()) {
|
||||||
|
env.pending('Environment does not support URLs');
|
||||||
|
}
|
||||||
|
};
|
||||||
|
})(jasmine.getEnv());
|
||||||
@@ -24,6 +24,7 @@ module.exports = {
|
|||||||
'helpers/checkForSet.js',
|
'helpers/checkForSet.js',
|
||||||
'helpers/checkForSymbol.js',
|
'helpers/checkForSymbol.js',
|
||||||
'helpers/checkForTypedArrays.js',
|
'helpers/checkForTypedArrays.js',
|
||||||
|
'helpers/checkForUrl.js',
|
||||||
'helpers/domHelpers.js',
|
'helpers/domHelpers.js',
|
||||||
'helpers/integrationMatchers.js',
|
'helpers/integrationMatchers.js',
|
||||||
'helpers/promises.js',
|
'helpers/promises.js',
|
||||||
|
|||||||
@@ -11,6 +11,7 @@
|
|||||||
"helpers/checkForSet.js",
|
"helpers/checkForSet.js",
|
||||||
"helpers/checkForSymbol.js",
|
"helpers/checkForSymbol.js",
|
||||||
"helpers/checkForTypedArrays.js",
|
"helpers/checkForTypedArrays.js",
|
||||||
|
"helpers/checkForUrl.js",
|
||||||
"helpers/domHelpers.js",
|
"helpers/domHelpers.js",
|
||||||
"helpers/integrationMatchers.js",
|
"helpers/integrationMatchers.js",
|
||||||
"helpers/promises.js",
|
"helpers/promises.js",
|
||||||
|
|||||||
@@ -161,6 +161,15 @@ getJasmineRequireObj().base = function(j$, jasmineGlobal) {
|
|||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
j$.isURL = function(obj) {
|
||||||
|
return (
|
||||||
|
obj !== null &&
|
||||||
|
typeof obj !== 'undefined' &&
|
||||||
|
typeof jasmineGlobal.URL !== 'undefined' &&
|
||||||
|
obj.constructor === jasmineGlobal.URL
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
j$.isDataView = function(obj) {
|
j$.isDataView = function(obj) {
|
||||||
return (
|
return (
|
||||||
obj !== null &&
|
obj !== null &&
|
||||||
|
|||||||
@@ -475,6 +475,10 @@ getJasmineRequireObj().MatchersUtil = function(j$) {
|
|||||||
diffBuilder.recordMismatch();
|
diffBuilder.recordMismatch();
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
} else if (j$.isURL(a) && j$.isURL(b)) {
|
||||||
|
// URLs have no enumrable properties, so the default object comparison
|
||||||
|
// would consider any two URLs to be equal.
|
||||||
|
return a.toString() === b.toString();
|
||||||
} else {
|
} else {
|
||||||
// Objects with different constructors are not equivalent, but `Object`s
|
// Objects with different constructors are not equivalent, but `Object`s
|
||||||
// or `Array`s from different frames are.
|
// or `Array`s from different frames are.
|
||||||
|
|||||||
Reference in New Issue
Block a user