File tree 3 files changed +29
-6
lines changed
3 files changed +29
-6
lines changed Original file line number Diff line number Diff line change
1
+ import React from 'react' ;
2
+
3
+ const Task = ( props ) => {
4
+ return < li > { props . name } </ li > ;
5
+ } ;
6
+
7
+ export default Task ;
Original file line number Diff line number Diff line change 1
1
import React from 'react' ;
2
+ import Task from './Task' ;
2
3
3
4
const ToDoList = ( props ) => {
4
5
return (
5
6
< ul >
6
- { props . tasks . map ( ( taskName , index ) => (
7
- < li key = { index } > { taskName } </ li >
7
+ { props . tasks . map ( ( task ) => (
8
+ < Task key = { task . id } id = { task . id } name = { task . name } / >
8
9
) ) }
9
10
</ ul >
10
11
) ;
Original file line number Diff line number Diff line change @@ -17,10 +17,25 @@ describe('ToDoList component', () => {
17
17
} ) ;
18
18
19
19
describe ( 'when provided with an array of tasks' , ( ) => {
20
- it ( 'contains a matching number of <li> elements' , ( ) => {
21
- const tasks = [ 'Wash the dishes' , 'Make the bed' ] ;
22
- const toDoList = shallow ( < ToDoList tasks = { tasks } /> ) ;
23
- expect ( toDoList . find ( 'li' ) . length ) . toEqual ( tasks . length ) ;
20
+ const tasks = [
21
+ {
22
+ id : 0 ,
23
+ name : 'Wash the dishes' ,
24
+ } ,
25
+ {
26
+ id : 1 ,
27
+ name : 'Make the bed' ,
28
+ } ,
29
+ ] ;
30
+
31
+ it ( 'passes them to the Task components' , ( ) => {
32
+ const toDoListInstance = shallow ( < ToDoList tasks = { tasks } /> ) ;
33
+
34
+ toDoListInstance . find ( 'Task' ) . forEach ( ( taskInstance ) => {
35
+ const taskProps = taskInstance . props ( ) ;
36
+ const matchingTask = tasks . find ( ( task ) => task . id === taskProps . id ) ;
37
+ expect ( taskProps . name ) . toBe ( matchingTask . name ) ;
38
+ } ) ;
24
39
} ) ;
25
40
} ) ;
26
41
} ) ;
You can’t perform that action at this time.
0 commit comments