Skip to content

Commit 4820060

Browse files
committed
add TodoList test
1 parent 9d6ebc4 commit 4820060

File tree

2 files changed

+40
-1
lines changed

2 files changed

+40
-1
lines changed

src/App/TodoList/index.test.tsx

+39
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
import React from 'react'
2+
import { render, cleanup } from '@testing-library/react'
3+
import Provider from 'muriatic'
4+
import '@testing-library/jest-dom/extend-expect'
5+
import TodoList from './index'
6+
import { Store } from '../../index'
7+
8+
const initialStore: Store = {
9+
todoList: [
10+
{
11+
id: 'TsHx9eEN5Y4A',
12+
bodyText: 'monster',
13+
completed: false
14+
},
15+
{
16+
id: 'ba91OwrK0Dt8',
17+
bodyText: 'boss black',
18+
completed: false
19+
},
20+
{ id: 'QwejYipEf5nk', bodyText: 'caffe latte', completed: false }
21+
]
22+
}
23+
24+
afterEach(cleanup)
25+
26+
test('should render stored todo values', () => {
27+
const { getByTestId, getAllByTestId } = render(
28+
<Provider store={initialStore}>
29+
<TodoList path="/" />
30+
</Provider>
31+
)
32+
33+
expect(getByTestId('todo-list')).toBeInTheDocument()
34+
expect(getByTestId('todo-list').children.length).toBe(3)
35+
expect(Array.isArray(getAllByTestId('todo-item'))).toBe(true)
36+
expect(getAllByTestId('todo-item')[0]).toHaveTextContent('monster')
37+
expect(getAllByTestId('todo-item')[1]).toHaveTextContent('boss black')
38+
expect(getAllByTestId('todo-item')[2]).toHaveTextContent('caffe latte')
39+
})

src/App/TodoList/index.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ function TodoList({ path }: Props) {
3333
data-cy="toggle-all-btn"
3434
/>
3535
<label htmlFor="toggle-all">Mark all as complete</label>
36-
<ul className="todo-list">
36+
<ul className="todo-list" data-testid="todo-list">
3737
{store.todoList
3838
.filter((t: Todo) => {
3939
switch (path) {

0 commit comments

Comments
 (0)