Debian Codegraph @

tests/unit/location.test.ts

raw
1 import { describe, expect, it } from 'vitest';
2 import { Location } from '../../src/helpers/Location.js';
3
4 describe('Location', () => {
5 it('has an href', () => {
6 const location = new Location('/path?query#anchor');
7 expect(location.href).to.eq('http://localhost:3000/path?query#anchor');
8 });
9 it('has a url', () => {
10 const location = new Location('/path?query#anchor');
11 expect(location.url).to.eq('/path?query');
12 });
13 it('accepts a base', () => {
14 const location = new Location('/path?query#anchor', 'http://base.net');
15 expect(location.href).to.eq('http://base.net/path?query#anchor');
16 });
17 it('accepts absolute URLs', () => {
18 const location = new Location('http://example.net/path?query#anchor', 'http://base.net');
19 expect(location.href).to.eq('http://example.net/path?query#anchor');
20 });
21 it('allows static creation', () => {
22 const location = Location.fromUrl('http://example.net/path?query#anchor');
23 expect(location.href).to.eq('http://example.net/path?query#anchor');
24 expect(location.url).to.eq('/path?query');
25 });
26 });