import { screen, render, fireEvent } from '@testing-library/react'; import { Tabs, Tab } from '../tabs'; describe('Tabs', () => { it('should render', () => { const { asFragment } = render( Title 1}>blah blaher blahest ); expect(asFragment()).toMatchSnapshot(); }); it('should render other default tab', () => { const { asFragment } = render( Title 1}>blah blaher blahest ); expect(asFragment()).toMatchSnapshot(); }); it('should render tabs and pass extra props', () => { const { asFragment } = render( Title 1} aria-label="blah!"> blah blaher blahest ); expect(asFragment()).toMatchSnapshot(); }); it('should show corresponding content when 2nd tab title is clicked', () => { render( Title 1}> blah blaher blahest ); let content = screen.queryByTestId('tab-content'); expect(content).not.toHaveTextContent('blaher'); const title = screen.queryAllByTestId('tab-title'); fireEvent.click(title[1]); content = screen.queryByTestId('tab-content'); expect(content).toHaveTextContent('blaher'); }); it('should show 2nd tab if defined as active', () => { render( Title 1}> blah-1 blaher ); const content = screen.queryByTestId('tab-content'); expect(content).not.toHaveTextContent('blah-1'); expect(content).toHaveTextContent('blaher'); }); it('should keep cached tab in document but not visible if not active', () => { render( Title 1}> blah-1 blaher ); // First tab is active so as usual expect(screen.queryByTestId('tab-content')).toHaveTextContent('blah-1'); // Second tab is inactive and cached so it should be in the document but not visible expect(screen.queryByText('blaher')).toBeInTheDocument(); expect(screen.queryByText('blaher')).not.toBeVisible(); }); });