File tree 2 files changed +40
-1
lines changed
2 files changed +40
-1
lines changed Original file line number Diff line number Diff line change
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
+ } )
Original file line number Diff line number Diff line change @@ -33,7 +33,7 @@ function TodoList({ path }: Props) {
33
33
data-cy = "toggle-all-btn"
34
34
/>
35
35
< label htmlFor = "toggle-all" > Mark all as complete</ label >
36
- < ul className = "todo-list" >
36
+ < ul className = "todo-list" data-testid = "todo-list" >
37
37
{ store . todoList
38
38
. filter ( ( t : Todo ) => {
39
39
switch ( path ) {
You can’t perform that action at this time.
0 commit comments