-
-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathrouting.test.ts
More file actions
35 lines (29 loc) · 1021 Bytes
/
routing.test.ts
File metadata and controls
35 lines (29 loc) · 1021 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
import { describe, it, expect } from 'vitest';
import { isActive } from './routing.js';
describe('isActive()', () => {
it('identifical path', () => {
const currentUrl = new URL('http://localhost/foo');
const path = '/foo';
expect(isActive(currentUrl, path)).true;
});
it('identifical path with query string', () => {
const currentUrl = new URL('http://localhost/foo?one=1');
const path = '/foo';
expect(isActive(currentUrl, path)).true;
});
it('nested path', () => {
const currentUrl = new URL('http://localhost/foo/bar');
const path = '/foo';
expect(isActive(currentUrl, path)).true;
});
it('same prefix but different path', () => {
const currentUrl = new URL('http://localhost/fo');
const path = '/foo';
expect(isActive(currentUrl, path)).false;
});
it('path should not match if not at beginning', () => {
const currentUrl = new URL('http://localhost/foo/bar');
const path = '/bar';
expect(isActive(currentUrl, path)).false;
});
});