Fixed comparison between URL objects

* Fixes #1866
This commit is contained in:
Steve Gravrock
2020-11-21 13:35:10 -08:00
parent 88de272c89
commit 89331bb1bb
8 changed files with 106 additions and 0 deletions

View File

@@ -62,4 +62,17 @@ describe('base helpers', function() {
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);
});
});
});

View File

@@ -837,6 +837,54 @@ describe('matchersUtil', function() {
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() {
var findIndexDescriptor = Object.getOwnPropertyDescriptor(
Array.prototype,