import React from 'react'; import renderer from 'react-test-renderer'; import { fireEvent, render } from '@testing-library/react'; import '@testing-library/jest-dom'; import { Gallery } from './Gallery'; jest.mock( 'react-image-lightbox', // eslint-disable-next-line react/display-name () => ({ onCloseRequest, mainSrc }: { onCloseRequest: () => void; mainSrc?: string }) => (
lightbox {mainSrc}
), ); const testData = [ 'https://source.unsplash.com/random/800x600', 'https://source.unsplash.com/random/800x601', 'https://source.unsplash.com/random/800x603', ]; describe('Gallery', () => { it('renders with an empty images array', () => { const tree = renderer.create().toJSON(); expect(tree).toMatchInlineSnapshot(`
`); }); it('renders with one image', () => { const tree = renderer.create().toJSON(); expect(tree).toMatchInlineSnapshot(`
`); }); it('renders with multiple images', () => { const tree = renderer.create().toJSON(); expect(tree).toMatchInlineSnapshot(`
`); }); it('renders Lightbox after click on one of the images', () => { const { getByAltText, getByText, container } = render(); fireEvent.click(getByAltText('')); expect(container.firstChild).toMatchInlineSnapshot(` `); fireEvent.click(getByText('lightbox')); expect(container.firstChild).toMatchInlineSnapshot(` `); }); });