diff --git a/package.json b/package.json index a4c50cb..8f6e3da 100644 --- a/package.json +++ b/package.json @@ -13,6 +13,26 @@ "prettify": "prettier --write **/*.{ts,tsx,js,jsx,json}", "format": "prettier --write 'src/**/*.{ts,tsx,scss,css,json}'" }, + "jest": { + "coveragePathIgnorePatterns": [ + "node_modules", + "test-config", + "interfaces", + "jestGlobalMocks.ts", + ".module.ts", + "/src/App.tsx", + "/src/index.tsx", + "/src/reportWebVitals.ts" + ], + "coverageThreshold": { + "global": { + "statements": 80, + "branches": 80, + "functions": 80, + "lines": 80 + } + } + }, "husky": { "hooks": { "pre-commit": "lint-staged" diff --git a/src/components/__tests__/SearchForm.test.tsx b/src/components/__tests__/SearchForm.test.tsx index 9888916..b4d75f5 100644 --- a/src/components/__tests__/SearchForm.test.tsx +++ b/src/components/__tests__/SearchForm.test.tsx @@ -1,5 +1,5 @@ import React from 'react'; -import { render, screen } from '@testing-library/react'; +import { render, screen, waitFor } from '@testing-library/react'; import { Router } from 'react-router-dom'; import SearchForm from 'components/SearchForm'; import { createMemoryHistory } from 'history'; @@ -15,7 +15,7 @@ const renderWithRoute = (path: string) => { ); }; -describe('NavBar', () => { +describe('SearchForm', () => { test('should render search form with empty input on movies route', () => { renderWithRoute('/movies'); const input = screen.getByRole('textbox') as HTMLInputElement; @@ -32,7 +32,7 @@ describe('NavBar', () => { expect(input.value).toEqual(query); }); - test('should change input value when user types', () => { + test('should change input value when user types', async () => { const query = 'red'; renderWithRoute('/movies'); const input = screen.getByRole('textbox') as HTMLInputElement; @@ -40,6 +40,6 @@ describe('NavBar', () => { expect(input.value).toEqual(''); userEvent.type(input, query); - expect(input.value).toEqual(query); + await waitFor(() => expect(input.value).toEqual(query)); }); }); diff --git a/src/hoc/__tests__/withErrorHandler.integration.test.tsx b/src/hoc/__tests__/withErrorHandler.integration.test.tsx index 535cbe6..5f36f6e 100644 --- a/src/hoc/__tests__/withErrorHandler.integration.test.tsx +++ b/src/hoc/__tests__/withErrorHandler.integration.test.tsx @@ -45,7 +45,5 @@ describe('Integration test between useHttpErrorHandler hook and withErrorHandler expect(screen.queryByTestId('close-button')).not.toBeInTheDocument(); expect(screen.queryByText('Error')).not.toBeInTheDocument(); expect(screen.queryByText(`${axiosError.message}`)).not.toBeInTheDocument(); - - screen.debug(); }); }); diff --git a/src/pages/__tests__/Home.test.tsx b/src/pages/__tests__/Home.test.tsx index 2c42c46..b37bfd3 100644 --- a/src/pages/__tests__/Home.test.tsx +++ b/src/pages/__tests__/Home.test.tsx @@ -34,22 +34,22 @@ describe('Home', () => { mockFetchGenres.mockResolvedValueOnce(genres); mockGetMovies.mockResolvedValueOnce(moviesResponse); }); - // test('should render loading spinner', async () => { - // const history = createMemoryHistory(); - // history.push(`/movies/${category}`); - // render( - // - // - // - // - // - // - // - // - // - // ); - // await waitFor(() => expect(screen.getByTestId('spinner')).toBeInTheDocument()); - // }); + test('should render loading spinner', async () => { + const history = createMemoryHistory(); + history.push(`/movies/${category}`); + render( + + + + + + + + + , + ); + await waitFor(() => expect(screen.getByTestId('spinner')).toBeInTheDocument()); + }); test('should render movie list', async () => { const history = createMemoryHistory();