router.test.tsx 966 B

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