Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

index.spec.tsx 1.6KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. import React from 'react'
  2. import { render } from '@testing-library/react'
  3. import '@testing-library/jest-dom'
  4. import Spinner from './index'
  5. describe('Spinner component', () => {
  6. it('should render correctly when loading is true', () => {
  7. const { container } = render(<Spinner loading={true} />)
  8. const spinner = container.firstChild as HTMLElement
  9. expect(spinner).toHaveClass('animate-spin')
  10. // Check for accessibility text
  11. const screenReaderText = spinner.querySelector('span')
  12. expect(screenReaderText).toBeInTheDocument()
  13. expect(screenReaderText).toHaveTextContent('Loading...')
  14. })
  15. it('should be hidden when loading is false', () => {
  16. const { container } = render(<Spinner loading={false} />)
  17. const spinner = container.firstChild as HTMLElement
  18. expect(spinner).toHaveClass('hidden')
  19. })
  20. it('should render with custom className', () => {
  21. const customClass = 'text-blue-500'
  22. const { container } = render(<Spinner loading={true} className={customClass} />)
  23. const spinner = container.firstChild as HTMLElement
  24. expect(spinner).toHaveClass(customClass)
  25. })
  26. it('should render children correctly', () => {
  27. const childText = 'Child content'
  28. const { getByText } = render(
  29. <Spinner loading={true}>{childText}</Spinner>,
  30. )
  31. expect(getByText(childText)).toBeInTheDocument()
  32. })
  33. it('should use default loading value (false) when not provided', () => {
  34. const { container } = render(<Spinner />)
  35. const spinner = container.firstChild as HTMLElement
  36. expect(spinner).toHaveClass('hidden')
  37. })
  38. })