ErrorBoundary.test.tsx 748 B

123456789101112131415161718192021222324252627282930
  1. import { describe, it, expect, vi } from 'vitest'
  2. import { render, screen } from '@testing-library/react'
  3. import { ErrorBoundary } from '@/components/ErrorBoundary'
  4. const ThrowError = () => {
  5. throw new Error('test error')
  6. }
  7. describe('ErrorBoundary', () => {
  8. it('renders children when no error', () => {
  9. render(
  10. <ErrorBoundary>
  11. <div>hello</div>
  12. </ErrorBoundary>,
  13. )
  14. expect(screen.getByText('hello')).toBeInTheDocument()
  15. })
  16. it('renders fallback on error', () => {
  17. vi.spyOn(console, 'debug').mockImplementation(() => {})
  18. render(
  19. <ErrorBoundary>
  20. <ThrowError />
  21. </ErrorBoundary>,
  22. )
  23. expect(screen.getByText('Что-то пошло не так')).toBeInTheDocument()
  24. })
  25. })