diff --git a/src/components/Card/Card.test.tsx b/src/components/Card/Card.test.tsx index f39785eff..be3d4709a 100644 --- a/src/components/Card/Card.test.tsx +++ b/src/components/Card/Card.test.tsx @@ -1,49 +1,33 @@ import * as React from 'react'; -import { fireEvent, render } from '@testing-library/react'; -import { BrowserRouter } from 'react-router-dom'; +import { fireEvent } from '@testing-library/react'; import Card from './Card'; import type { PlaylistItem } from '#types/playlist'; +import { renderWithRouter } from '#test/testUtils'; const item = { title: 'aa', duration: 120 } as PlaylistItem; const itemWithImage = { title: 'This is a movie', duration: 120, cardImage: 'http://movie.jpg' } as PlaylistItem; describe('', () => { it('renders card with video title', () => { - const { getByText } = render( - - ''} /> - , - ); + const { getByText } = renderWithRouter( ''} />); expect(getByText(/aa/i)).toBeTruthy(); }); it('renders tag with correct duration', () => { - const { getByText } = render( - - ''} /> - , - ); + const { getByText } = renderWithRouter( ''} />); expect(getByText(/2/i)).toBeTruthy(); }); it('renders the image with the image prop when valid', () => { - const { getByAltText } = render( - - ''} /> - , - ); + const { getByAltText } = renderWithRouter( ''} />); expect(getByAltText('This is a movie')).toHaveAttribute('src', 'http://movie.jpg?width=320'); }); it('makes the image visible after load', () => { - const { getByAltText } = render( - - ''} /> - , - ); + const { getByAltText } = renderWithRouter( ''} />); expect(getByAltText('This is a movie')).toHaveAttribute('src', 'http://movie.jpg?width=320'); expect(getByAltText('This is a movie')).toHaveStyle({ opacity: 0 }); diff --git a/src/components/CardGrid/CardGrid.test.tsx b/src/components/CardGrid/CardGrid.test.tsx index a245e4f03..ba3775030 100644 --- a/src/components/CardGrid/CardGrid.test.tsx +++ b/src/components/CardGrid/CardGrid.test.tsx @@ -1,26 +1,23 @@ import * as React from 'react'; -import { render } from '@testing-library/react'; -import { BrowserRouter } from 'react-router-dom'; import CardGrid from './CardGrid'; import { generatePlaylistPlaceholder } from '#src/utils/collection'; +import { renderWithRouter } from '#test/testUtils'; describe('', () => { it('renders and matches snapshot', () => { const placeholderData = generatePlaylistPlaceholder(); - const { container } = render( - - - , + const { container } = renderWithRouter( + , ); expect(container).toMatchSnapshot(); diff --git a/src/components/Shelf/Shelf.test.tsx b/src/components/Shelf/Shelf.test.tsx index 1103aa9c4..43fa0e73b 100644 --- a/src/components/Shelf/Shelf.test.tsx +++ b/src/components/Shelf/Shelf.test.tsx @@ -1,8 +1,7 @@ import React from 'react'; -import { render } from '@testing-library/react'; -import { BrowserRouter } from 'react-router-dom'; import Shelf from '#components/Shelf/Shelf'; +import { renderWithRouter } from '#test/testUtils'; const playlist = { playlist: [ @@ -60,39 +59,35 @@ const playlist = { describe('Shelf Component tests', () => { test('Regular shelf', () => { - const { container } = render( - - - , + const { container } = renderWithRouter( + , ); expect(container).toMatchSnapshot(); }); test('Featured shelf', () => { - const { container } = render( - - - , + const { container } = renderWithRouter( + , ); expect(container).toMatchSnapshot();