2023-09-15 16:14:47 +03:00
|
|
|
import * as assert from 'assert/strict';
|
2023-09-20 19:53:10 +03:00
|
|
|
import {trimHash, trimSearch, trimSearchAndHash} from '../../../src/utils/url';
|
2023-09-15 16:14:47 +03:00
|
|
|
|
|
|
|
describe('trimSearch', function () {
|
|
|
|
it('removes the query parameters from a URL', function () {
|
|
|
|
const url = 'https://example.com/?foo=bar&baz=qux';
|
|
|
|
const parsedUrl = new URL(url);
|
|
|
|
|
|
|
|
assert.equal(trimSearch(parsedUrl).toString(), 'https://example.com/');
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('trimHash', function () {
|
|
|
|
it('removes the hash fragment from a URL', function () {
|
|
|
|
const url = 'https://example.com/path#section-1';
|
|
|
|
const parsedUrl = new URL(url);
|
|
|
|
|
|
|
|
assert.equal(trimHash(parsedUrl).toString(), 'https://example.com/path');
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('trimSearchAndHash', function () {
|
|
|
|
it('removes the hash fragment from a URL', function () {
|
|
|
|
const url = 'https://example.com/path#section-1?foo=bar&baz=qux';
|
|
|
|
const parsedUrl = new URL(url);
|
|
|
|
|
|
|
|
assert.equal(trimSearchAndHash(parsedUrl).toString(), 'https://example.com/path');
|
|
|
|
});
|
|
|
|
});
|