import { useNavigation } from '../router' import { vi, test, expect, afterAll, describe } from 'vitest' import * as message from '../message' vi.mock('next/router', async (importOriginal) => { const mod = await importOriginal() return { ...mod, // replace some exports useRouter: vi.fn(() => ({ push: vi.fn(), })), } }) describe('router', () => { afterAll(() => { vi.doUnmock('next/router') }) test('navigate should publish message with path', async () => { vi.spyOn(message, 'publishMessage') const { navigate } = useNavigation() navigate('/test') expect(message.publishMessage).toHaveBeenCalledWith({ type: 'navigation', data: { path: '/test', }, }) }) test('navigate should log warning if path does not start with /', () => { const mockConsoleWarn = vi .spyOn(console, 'warn') .mockImplementation(() => {}) const { navigate } = useNavigation() navigate('test') expect(mockConsoleWarn).toHaveBeenCalledWith('The path must start with /') }) })