|
1 | 1 | import { describe, expect, it } from 'vitest';
|
2 | 2 |
|
3 |
| -import { isUri, toURL } from './uri'; |
| 3 | +import { isEqual, isUri, toURL } from './uri'; |
4 | 4 |
|
5 | 5 | describe('isUri', () => {
|
6 | 6 | it('should return a boolean indicating if the provided string is a valid URI', () => {
|
@@ -28,3 +28,50 @@ describe('toURL', () => {
|
28 | 28 | expect(toURL('://example.com/user/foo')).toBeUndefined();
|
29 | 29 | });
|
30 | 30 | });
|
| 31 | + |
| 32 | +describe('isEqual', () => { |
| 33 | + it('should compare string URLs correctly', () => { |
| 34 | + expect(isEqual('https://example.com', 'https://example.com/')).toBe( |
| 35 | + true, |
| 36 | + ); |
| 37 | + expect(isEqual('https://example.com', 'https://example.com')).toBe( |
| 38 | + true, |
| 39 | + ); |
| 40 | + expect(isEqual('https://example.com/', 'https://example.com/')).toBe( |
| 41 | + true, |
| 42 | + ); |
| 43 | + expect(isEqual('https://example.com', 'https://example.org')).toBe( |
| 44 | + false, |
| 45 | + ); |
| 46 | + }); |
| 47 | + |
| 48 | + it('should compare URL objects correctly', () => { |
| 49 | + const url1 = new URL('https://example.com'); |
| 50 | + const url2 = new URL('https://example.com/'); |
| 51 | + const url3 = new URL('https://example.org'); |
| 52 | + |
| 53 | + expect(isEqual(url1, url1)).toBe(true); |
| 54 | + expect(isEqual(url1, url2)).toBe(true); |
| 55 | + expect(isEqual(url2, url3)).toBe(false); |
| 56 | + expect(isEqual(url1, url3)).toBe(false); |
| 57 | + }); |
| 58 | + |
| 59 | + it('should compare mixed URL objects and strings correctly', () => { |
| 60 | + const url = new URL('https://example.com'); |
| 61 | + |
| 62 | + expect(isEqual(url, 'https://example.com/')).toBe(true); |
| 63 | + expect(isEqual(url, 'https://example.org')).toBe(false); |
| 64 | + }); |
| 65 | + |
| 66 | + it('should handle URLs with paths', () => { |
| 67 | + expect( |
| 68 | + isEqual('https://example.com/path', 'https://example.com/path/'), |
| 69 | + ).toBe(true); |
| 70 | + expect( |
| 71 | + isEqual( |
| 72 | + 'https://example.com/path', |
| 73 | + 'https://example.com/other-path', |
| 74 | + ), |
| 75 | + ).toBe(false); |
| 76 | + }); |
| 77 | +}); |
0 commit comments