Skip to content
Merged
Show file tree
Hide file tree
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,4 @@ node_modules
.nyc_output
coverage.lcov
yarn-error.log
package-lock.json
4 changes: 1 addition & 3 deletions src/url-browser.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
'use strict';

const defaultBase = self.location ?
self.location.protocol + '//' + self.location.host :
'';
const defaultBase = self.location && self.location.protocol + '//' + self.location.host;
const URL = self.URL;

class URLWithLegacySupport {
Expand Down
20 changes: 20 additions & 0 deletions test.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,26 @@ const isBrowser =
typeof document === 'object' &&
document.nodeType === 9;

test('unspecified base should not throw', (t) => {
t.plan(1);

if (isBrowser) {
t.doesNotThrow(() => new URL('http://localhost'));
} else {
// Hack to force construction of a browser URL in Node to simulate a React Native-like environment where .location does not exist
global.self = {
URL: global.URL,
URLSearchParams: global.URLSearchParams
};
/* eslint-disable-next-line global-require */
const { URLWithLegacySupport: URL } = require('./src/url-browser');

t.doesNotThrow(() => new URL('http://localhost'));

delete global.self;
}
});

test('relative', (t) => {
t.plan(1);

Expand Down