import { render, screen } from '@testing-library/react'; import Text from './index'; describe('Text', () => { it('should render text', () => { render(Hello World); expect(screen.getByText('Hello World')).toMatchInlineSnapshot(` .emotion-0 { font-size: 14px; font-weight: 400; line-height: 20px; letter-spacing: 0.25px; margin: 0px; }
Hello World
`); }); it('should render text in h1Bold variant', () => { render(H1 Hello World); expect(screen.getByText('H1 Hello World')).toHaveStyle( 'font-size: 32px; font-weight: 700;' ); }); it('should render text in red color', () => { render(I look red); expect(screen.getByText('I look red')).toHaveStyle('color: red;'); }); it('should apply truncate styles', () => { const lorem = 'Lorem ipsum dolor sit amet consectetur adipisicing elit. Soluta, similique.'; render({lorem}); expect(screen.getByText(lorem)).toMatchInlineSnapshot(` .emotion-0 { font-size: 14px; font-weight: 400; line-height: 20px; letter-spacing: 0.25px; overflow: hidden; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; margin: 0px; }
Lorem ipsum dolor sit amet consectetur adipisicing elit. Soluta, similique.
`); }); it('should render as paragraph instead of div', () => { render(I am a paragraph); expect(screen.getByText(/paragraph/).tagName).toBe('P'); }); it.each([ { prop: 'margin', style: 'margin', value: 10 }, { prop: 'marginTop', style: 'margin-top', value: 10 }, { prop: 'marginRight', style: 'margin-right', value: 10 }, { prop: 'marginBottom', style: 'margin-bottom', value: 10 }, { prop: 'marginLeft', style: 'margin-left', value: 10 }, ])('should apply appropriate margin styles', ({ prop, style, value }) => { render(I have margin); expect(screen.getByText(/margin/)).toHaveStyle(`${style}: ${value}px;`); }); it('should apply line-height in px in text', () => { render(I have line-height in px); expect(screen.getByText(/line-height/)).toHaveStyle('line-height: 32px;'); }); });