diff --git a/src/App/NewTodoInput/index.test.tsx b/src/App/NewTodoInput/index.test.tsx index a10c9094..ef40edb8 100644 --- a/src/App/NewTodoInput/index.test.tsx +++ b/src/App/NewTodoInput/index.test.tsx @@ -1,12 +1,12 @@ import { fireEvent } from '@testing-library/react' import React from 'react' -import { renderWithRecoilRoot } from '../../testUtil' +import { TestRenderer } from '../../testUtil' import NewTodoTextInput from './index' test('should be render ', () => { - const screen = renderWithRecoilRoot() + const screen = TestRenderer() const input = screen.getByTestId('new-todo-input-text') as HTMLInputElement // Header big text diff --git a/src/App/TodoList/Item/index.test.tsx b/src/App/TodoList/Item/index.test.tsx index 4f5b61fa..110e56e0 100644 --- a/src/App/TodoList/Item/index.test.tsx +++ b/src/App/TodoList/Item/index.test.tsx @@ -4,7 +4,7 @@ import { useRecoilState } from 'recoil' import type { AppState } from '../../../dataStructure' import { recoilState } from '../../../dataStructure' -import { renderWithRecoilRoot } from '../../../testUtil' +import { TestRenderer } from '../../../testUtil' import Item from './index' @@ -29,7 +29,7 @@ const App = () => { } test('should each initialAppstate todo object value is set to Item element', () => { - renderWithRecoilRoot( + TestRenderer( , initialRecoilState ) @@ -46,7 +46,7 @@ test('should each initialAppstate todo object value is set to Item element', () }) test('should set css classes correctly', () => { - renderWithRecoilRoot(, initialRecoilState) + TestRenderer(, initialRecoilState) // when not.completed & not.onEdit, SwitchStyle doesn't show .completed .editting selectors expect(screen.getByTestId('todo-item')).not.toHaveClass('completed') @@ -54,7 +54,7 @@ test('should set css classes correctly', () => { }) test('should work todo completed checkbox', () => { - renderWithRecoilRoot(, initialRecoilState) + TestRenderer(, initialRecoilState) // click complete checkbox then should appear completed class fireEvent.click(screen.getByTestId('todo-item-complete-check')) @@ -72,7 +72,7 @@ test('should work todo completed checkbox', () => { }) test('should work edit mode and toggle show/hide', () => { - renderWithRecoilRoot(, initialRecoilState) + TestRenderer(, initialRecoilState) // by default, edit input form is not visible expect(screen.getByTestId('todo-edit-input')).not.toBeVisible() @@ -109,7 +109,7 @@ test('should work edit mode and toggle show/hide', () => { }) test('delete todo item', () => { - renderWithRecoilRoot(, initialRecoilState) + TestRenderer(, initialRecoilState) // click delete button, then todo item is removed expect(screen.getByTestId('todo-item')).toBeInTheDocument() diff --git a/src/App/TodoList/index.test.tsx b/src/App/TodoList/index.test.tsx index 05f78331..23c2c99f 100644 --- a/src/App/TodoList/index.test.tsx +++ b/src/App/TodoList/index.test.tsx @@ -2,7 +2,7 @@ import { fireEvent } from '@testing-library/react' import React from 'react' import type { AppState } from '../../dataStructure' -import { renderWithRecoilRoot } from '../../testUtil' +import { TestRenderer } from '../../testUtil' import TodoList from './index' @@ -27,7 +27,7 @@ const initialRecoilState: AppState = { } test('should be render 3 todo items in initialAppState', () => { - const screen = renderWithRecoilRoot(, initialRecoilState) + const screen = TestRenderer(, initialRecoilState) expect(screen.getByTestId('todo-list')).toBeInTheDocument() expect(screen.getByTestId('todo-list').children.length).toBe(3) @@ -38,7 +38,7 @@ test('should be render 3 todo items in initialAppState', () => { }) test('should be work delete todo button', () => { - const screen = renderWithRecoilRoot(, initialRecoilState) + const screen = TestRenderer(, initialRecoilState) // delete first item fireEvent.click(screen.getAllByTestId('delete-todo-btn')[0]) @@ -50,7 +50,7 @@ test('should be work delete todo button', () => { }) test('should be work correctly all completed:true|false checkbox toggle button', () => { - const screen = renderWithRecoilRoot(, initialRecoilState) + const screen = TestRenderer(, initialRecoilState) // toggle on fireEvent.click(screen.getByTestId('toggle-all-btn')) diff --git a/src/App/index.tsx b/src/App/index.tsx index 8c0226ba..41e062ba 100644 --- a/src/App/index.tsx +++ b/src/App/index.tsx @@ -12,6 +12,8 @@ const App: React.FC = () => ( } /> + } /> + } /> } /> diff --git a/src/NotFound.tsx b/src/NotFound.tsx index de7610f8..a531b09b 100644 --- a/src/NotFound.tsx +++ b/src/NotFound.tsx @@ -1,4 +1,3 @@ -import type { RouteComponentProps } from '@reach/router' import React from 'react' const css: React.CSSProperties = { @@ -9,7 +8,7 @@ const css: React.CSSProperties = { width: '100%', } -export const NotFound: React.FC = () => ( +export const NotFound: React.FC = () => (

Page Not Found

diff --git a/src/testUtil.tsx b/src/testUtil.tsx index 7fd79f9e..c36e0a4d 100644 --- a/src/testUtil.tsx +++ b/src/testUtil.tsx @@ -1,6 +1,7 @@ import type { RenderResult } from '@testing-library/react' import { render } from '@testing-library/react' import React from 'react' +import { BrowserRouter } from 'react-router-dom' import type { MutableSnapshot } from 'recoil' import { RecoilRoot } from 'recoil' @@ -11,16 +12,18 @@ const defaultValue: AppState = { todoList: [], } -export const renderWithRecoilRoot = ( +export const TestRenderer = ( ui: React.ReactElement, initialRecoilStateValue: AppState = defaultValue ): RenderResult => render( - - set(recoilState, initialRecoilStateValue) - } - > - {ui} - + + + set(recoilState, initialRecoilStateValue) + } + > + {ui} + + )