|
| 1 | +import { describe, it, expect } from 'vitest'; |
| 2 | +import { render, screen } from '@testing-library/react'; |
| 3 | +import { createRef } from 'react'; |
| 4 | +import { Body } from './Body'; |
| 5 | + |
| 6 | +describe('Body', () => { |
| 7 | + it('renders children', () => { |
| 8 | + render( |
| 9 | + <Body> |
| 10 | + <p>Inhoud</p> |
| 11 | + </Body> |
| 12 | + ); |
| 13 | + expect(screen.getByText('Inhoud')).toBeInTheDocument(); |
| 14 | + }); |
| 15 | + |
| 16 | + it('renders as a <div> element', () => { |
| 17 | + const { container } = render(<Body />); |
| 18 | + expect(container.firstChild?.nodeName).toBe('DIV'); |
| 19 | + }); |
| 20 | + |
| 21 | + it('always has base dsn-body class', () => { |
| 22 | + const { container } = render(<Body />); |
| 23 | + expect(container.firstChild).toHaveClass('dsn-body'); |
| 24 | + }); |
| 25 | + |
| 26 | + it('applies custom className', () => { |
| 27 | + const { container } = render(<Body className="custom" />); |
| 28 | + expect(container.firstChild).toHaveClass('dsn-body'); |
| 29 | + expect(container.firstChild).toHaveClass('custom'); |
| 30 | + }); |
| 31 | + |
| 32 | + it('forwards ref to the div element', () => { |
| 33 | + const ref = createRef<HTMLDivElement>(); |
| 34 | + const { container } = render(<Body ref={ref} />); |
| 35 | + expect(ref.current).toBe(container.firstChild); |
| 36 | + }); |
| 37 | + |
| 38 | + it('passes additional HTML attributes', () => { |
| 39 | + const { container } = render(<Body data-testid="body" id="root" />); |
| 40 | + expect(container.firstChild).toHaveAttribute('data-testid', 'body'); |
| 41 | + expect(container.firstChild).toHaveAttribute('id', 'root'); |
| 42 | + }); |
| 43 | +}); |
0 commit comments