router.test.tsx32 lines · main
1import { render, screen, waitFor } from '@testing-library/react'
2import { expect, suite, test } from 'vitest'
3
4import { routerMock } from '../lib/route-mock'
5import { RouterComponent } from './router'
6
7suite('Router Mock', () => {
8 test('Router mock works as expected', async () => {
9 const comp = render(<RouterComponent />)
10 expect(comp.container.textContent).toContain('path: /')
11 expect(routerMock.pathname).toBe('/')
12 })
13
14 test('Clicking on link changes the path', async () => {
15 const comp = render(<RouterComponent />)
16
17 const link = screen.getByRole('link')
18
19 link.click()
20
21 waitFor(() => {
22 expect(routerMock.pathname).toBe('/test')
23 expect(comp.container.textContent).toContain('path: /test')
24 })
25 })
26
27 test('Router mock is reset after each test', async () => {
28 const comp = render(<RouterComponent />)
29 expect(comp.container.textContent).toContain('path: /')
30 expect(routerMock.pathname).toBe('/')
31 })
32})