blob: d79abc13d7b53556695e30a4169fb5900d633d3c (
plain) (
blame)
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
36
37
|
import { describe, it, expect, vi } from 'vitest';
import { router } from './router';
describe('Router', () => {
it('should parse simple paths', () => {
// Mock window.location
vi.stubGlobal('location', {
href: 'http://localhost/v3/feed/123',
pathname: '/v3/feed/123'
});
const route = router.getCurrentRoute();
expect(route.path).toBe('/feed');
expect(route.params.feedId).toBe('123');
});
it('should parse tags correctly', () => {
vi.stubGlobal('location', {
href: 'http://localhost/v3/tag/Tech%20News',
pathname: '/v3/tag/Tech%20News'
});
const route = router.getCurrentRoute();
expect(route.path).toBe('/tag');
expect(route.params.tagName).toBe('Tech News');
});
it('should parse query parameters', () => {
vi.stubGlobal('location', {
href: 'http://localhost/v3/?filter=starred',
pathname: '/v3/'
});
const route = router.getCurrentRoute();
expect(route.query.get('filter')).toBe('starred');
});
});
|