From 5ca3ce0af119e0c035bdbd379c98006d35c95021 Mon Sep 17 00:00:00 2001 From: digression99 Date: Tue, 20 Sep 2022 10:00:15 +0900 Subject: [PATCH] initialize test --- components/Counter.spec.tsx | 35 +-- components/FilteredTodoList.spec.tsx | 77 +------ .../__snapshots__/Counter.spec.tsx.snap | 164 -------------- .../FilteredTodoList.spec.tsx.snap | 209 ------------------ 4 files changed, 2 insertions(+), 483 deletions(-) delete mode 100644 components/__snapshots__/Counter.spec.tsx.snap delete mode 100644 components/__snapshots__/FilteredTodoList.spec.tsx.snap diff --git a/components/Counter.spec.tsx b/components/Counter.spec.tsx index 53c8f59..a12d60d 100644 --- a/components/Counter.spec.tsx +++ b/components/Counter.spec.tsx @@ -1,36 +1,3 @@ import { render } from '@testing-library/react' -import { PureCounter } from './Counter' -describe('', () => { - test('renders the component correctly', () => { - const { container: container1 } = render() - - expect(container1).toMatchSnapshot() - - const { container: container2 } = render() - expect(container2).toMatchSnapshot() - }) - - test('renders the special component correctly', () => { - const { container } = render() - expect(container).toMatchSnapshot() - }) -}) \ No newline at end of file +describe('', () => {}) \ No newline at end of file diff --git a/components/FilteredTodoList.spec.tsx b/components/FilteredTodoList.spec.tsx index 1b3c612..c1cd0ff 100644 --- a/components/FilteredTodoList.spec.tsx +++ b/components/FilteredTodoList.spec.tsx @@ -1,6 +1,4 @@ -import { render, screen } from '@testing-library/react' import { FilteredTodoList, PureFilteredTodoList, Todo } from './FilteredTodoList' -import userEvent from '@testing-library/user-event' const fakeData: Todo[] = [ { title: 'Test todo 1', completed: false, id: 'test-id-1' }, @@ -9,77 +7,4 @@ const fakeData: Todo[] = [ { title: 'Test todo 4', completed: true, id: 'test-id-4' }, ] -describe('', () => { - test('renders the component correctly', () => { - const { container } = render( - - ) - expect(container).toMatchSnapshot() - }) - - test('Add todo with a text, and it calls the method.', async () => { - const user = userEvent.setup() - const addTodoFn = jest.fn() - render( - - ) - const input = screen.getByRole('textbox', { name: 'title' }) - await user.type(input, 'Test todo 5') - const createButton = screen.getByRole('button', { name: 'Create' }) - await user.click(createButton) - expect(addTodoFn).toBeCalledWith('Test todo 5') - }) - - test('Add todo with a text, and it shows on the list', async () => { - const user = userEvent.setup() - render() - - const input = screen.getByRole('textbox', { name: 'title' }) - await user.type(input, 'Test todo 1') - const createButton = screen.getByRole('button', { name: 'Create' }) - await user.click(createButton) - expect(screen.getByText('Test todo 1')).toBeInTheDocument() - }) - - test('Change filter to "Completed" and it changes the list', async () => { - const user = userEvent.setup() - render() - - const input = screen.getByRole('textbox', { name: 'title' }) - await user.type(input, 'Test todo 1') - const createButton = screen.getByRole('button', { name: 'Create' }) - await user.click(createButton) - expect(screen.getByText('Test todo 1')).toBeInTheDocument() - - await user.type(input, 'Test todo 2') - await user.click(createButton) - expect(screen.getByText('Test todo 2')).toBeInTheDocument() - - const menu = await screen.findByText(/filters/i) - await user.click(menu) - const completedFilterButton = await screen.findByText(/completed/i) - await user.click(completedFilterButton) - expect(screen.queryAllByText(/Test todo/i)).toHaveLength(0) - - await user.click(menu) - const allFilterButton = await screen.findByText(/all/i) - await user.click(allFilterButton) - - // You can debug the screen with this method. - screen.debug() - expect(screen.getByText('Test todo 1')).toBeInTheDocument() - expect(screen.queryAllByText(/Test todo/i)).toHaveLength(2) - }) -}) +describe('', () => {}) diff --git a/components/__snapshots__/Counter.spec.tsx.snap b/components/__snapshots__/Counter.spec.tsx.snap deleted file mode 100644 index 9f9467b..0000000 --- a/components/__snapshots__/Counter.spec.tsx.snap +++ /dev/null @@ -1,164 +0,0 @@ -// Jest Snapshot v1, https://goo.gl/fbAQLP - -exports[` renders the component correctly 1`] = ` -
-
-
-

- Count : - 0 -

-
-
-

- Controllers -

- - - -
-
-

-

-
-
-`; - -exports[` renders the component correctly 2`] = ` -
-
-
-

- Count : - 100 -

-
-
-

- Controllers -

- - - -
-
-

- Count is max. -

-
-
-
-`; - -exports[` renders the special component correctly 1`] = ` -
-
-
-

- Count : - 30 -

-
-
-

- Controllers -

- - - -
-
-

- Count is min. -

-
-
-
-`; diff --git a/components/__snapshots__/FilteredTodoList.spec.tsx.snap b/components/__snapshots__/FilteredTodoList.spec.tsx.snap deleted file mode 100644 index 0132f77..0000000 --- a/components/__snapshots__/FilteredTodoList.spec.tsx.snap +++ /dev/null @@ -1,209 +0,0 @@ -// Jest Snapshot v1, https://goo.gl/fbAQLP - -exports[` renders the component correctly 1`] = ` -
-
-
-

- Todo Form -

- - -
- - -
    -
  • -

    - Test todo 1 -

    -
    - - -
    -
  • -
  • -

    - Test todo 2 -

    -
    - - -
    -
  • -
  • -

    - Test todo 3 -

    -
    - - -
    -
  • -
  • -

    - Test todo 4 -

    -
    - - -
    -
  • -
-
-
-`;