40 lines
1.2 KiB
TypeScript
40 lines
1.2 KiB
TypeScript
|
|
import { normalizeUrl } from './canonical-url';
|
||
|
|
|
||
|
|
describe('normalizeUrl', () => {
|
||
|
|
it('should remove protocol and www from URL', () => {
|
||
|
|
const url = 'https://www.example.com';
|
||
|
|
const expected = 'example.com';
|
||
|
|
expect(normalizeUrl(url)).toBe(expected);
|
||
|
|
});
|
||
|
|
|
||
|
|
it('should remove only protocol if www is not present', () => {
|
||
|
|
const url = 'https://example.com';
|
||
|
|
const expected = 'example.com';
|
||
|
|
expect(normalizeUrl(url)).toBe(expected);
|
||
|
|
});
|
||
|
|
|
||
|
|
it('should handle URLs without protocol', () => {
|
||
|
|
const url = 'www.example.com';
|
||
|
|
const expected = 'example.com';
|
||
|
|
expect(normalizeUrl(url)).toBe(expected);
|
||
|
|
});
|
||
|
|
|
||
|
|
it('should handle URLs without protocol and www', () => {
|
||
|
|
const url = 'example.com';
|
||
|
|
const expected = 'example.com';
|
||
|
|
expect(normalizeUrl(url)).toBe(expected);
|
||
|
|
});
|
||
|
|
|
||
|
|
it('should handle URLs with paths', () => {
|
||
|
|
const url = 'https://www.example.com/path/to/resource';
|
||
|
|
const expected = 'example.com';
|
||
|
|
expect(normalizeUrl(url)).toBe(expected);
|
||
|
|
});
|
||
|
|
|
||
|
|
it('should handle invalid URLs gracefully', () => {
|
||
|
|
const url = 'not a valid url';
|
||
|
|
const expected = 'not a valid url';
|
||
|
|
expect(normalizeUrl(url)).toBe(expected);
|
||
|
|
});
|
||
|
|
});
|