Files
nat-as-server/website/tests/unit/router.test.js
tom.hempel 06fc134299
Some checks failed
Tests / test (push) Has been cancelled
just testing the environment
2026-05-20 07:10:08 +02:00

33 lines
1.0 KiB
JavaScript

import { describe, it, expect, beforeEach } from 'vitest';
import { navigate, currentHash, matchRoute } from '../../js/router.js';
describe('router', () => {
beforeEach(() => {
window.location.hash = '';
});
it('currentHash defaults to / when empty', () => {
window.location.hash = '';
expect(currentHash()).toBe('/');
});
it('currentHash strips leading hash', () => {
window.location.hash = '#/dashboard';
expect(currentHash()).toBe('/dashboard');
});
it('navigate sets window hash', () => {
navigate('#/login');
expect(window.location.hash).toBe('#/login');
});
it('matchRoute extracts questionnaire id', () => {
const params = matchRoute('/questionnaire/:id', '/questionnaire/qn-123');
expect(params).toEqual({ id: 'qn-123' });
});
it('matchRoute returns null when path does not match', () => {
expect(matchRoute('/questionnaire/:id', '/users')).toBeNull();
});
});