Skip to content

Commit b09bab1

Browse files
committed
add TodoList store value mutation test
1 parent 4820060 commit b09bab1

File tree

1 file changed

+16
-1
lines changed

1 file changed

+16
-1
lines changed

src/App/TodoList/index.test.tsx

+16-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import React from 'react'
2-
import { render, cleanup } from '@testing-library/react'
2+
import { render, cleanup, fireEvent } from '@testing-library/react'
33
import Provider from 'muriatic'
44
import '@testing-library/jest-dom/extend-expect'
55
import TodoList from './index'
@@ -37,3 +37,18 @@ test('should render stored todo values', () => {
3737
expect(getAllByTestId('todo-item')[1]).toHaveTextContent('boss black')
3838
expect(getAllByTestId('todo-item')[2]).toHaveTextContent('caffe latte')
3939
})
40+
41+
test('should reflect store value change to render elements', () => {
42+
const { getByTestId, getAllByTestId } = render(
43+
<Provider store={initialStore}>
44+
<TodoList path="/" />
45+
</Provider>
46+
)
47+
48+
// delete first todo
49+
fireEvent.click(getAllByTestId('delete-todo-btn')[0])
50+
expect(getByTestId('todo-list').children.length).toBe(2)
51+
expect(Array.isArray(getAllByTestId('todo-item'))).toBe(true)
52+
expect(getAllByTestId('todo-item')[0]).toHaveTextContent('boss black')
53+
expect(getAllByTestId('todo-item')[1]).toHaveTextContent('caffe latte')
54+
})

0 commit comments

Comments
 (0)