@@ -46,19 +46,19 @@ test('should each todo object value is set to Item element', () => {
46
46
} )
47
47
48
48
test ( 'should correct render default class state' , ( ) => {
49
- const { container } = render (
49
+ const { getByTestId } = render (
50
50
< Provider store = { initialStore } >
51
51
< App />
52
52
</ Provider >
53
53
)
54
54
55
55
// when not.completed & not.onEdit, SwitchStyle doesn't show .completed .editting selectors
56
- expect ( container . querySelector ( '[class*="completed"] ') ) . toBe ( null )
57
- expect ( container . querySelector ( '[class*="editing"] ') ) . toBe ( null )
56
+ expect ( getByTestId ( 'todo-item ') ) . not . toHaveClass ( 'completed' )
57
+ expect ( getByTestId ( 'todo-item ') ) . not . toHaveClass ( 'editing' )
58
58
} )
59
59
60
60
test ( 'should work "check" complete toggle button' , ( ) => {
61
- const { getByTestId, container } = render (
61
+ const { getByTestId } = render (
62
62
< Provider store = { initialStore } >
63
63
< App />
64
64
</ Provider >
@@ -69,18 +69,18 @@ test('should work "check" complete toggle button', () => {
69
69
expect (
70
70
( getByTestId ( 'todo-item-complete-check' ) as HTMLInputElement ) . checked
71
71
) . toBe ( true )
72
- expect ( container . querySelector ( '[class*="completed"] ') ) . toBeInTheDocument ( )
72
+ expect ( getByTestId ( 'todo-item ') ) . toHaveClass ( 'completed' )
73
73
74
74
// should working as toggle
75
75
fireEvent . click ( getByTestId ( 'todo-item-complete-check' ) )
76
76
expect (
77
77
( getByTestId ( 'todo-item-complete-check' ) as HTMLInputElement ) . checked
78
78
) . toBe ( false )
79
- expect ( container . querySelector ( '[class*="completed"] ') ) . toBe ( null )
79
+ expect ( getByTestId ( 'todo-item ') ) . not . toHaveClass ( 'completed' )
80
80
} )
81
81
82
82
test ( 'should work edit mode toggle' , ( ) => {
83
- const { getByTestId, container } = render (
83
+ const { getByTestId } = render (
84
84
< Provider store = { initialStore } >
85
85
< App />
86
86
</ Provider >
@@ -90,9 +90,8 @@ test('should work edit mode toggle', () => {
90
90
expect ( getByTestId ( 'todo-edit-input' ) ) . not . toBeVisible ( )
91
91
92
92
// double click todo text label, then enable todo text edit code
93
-
94
93
fireEvent . doubleClick ( getByTestId ( 'todo-body-text' ) )
95
- expect ( container . querySelector ( '[class*="editing"] ') ) . toBeInTheDocument ( )
94
+ expect ( getByTestId ( 'todo-item ') ) . toHaveClass ( 'editing' )
96
95
// @TODO in jsdom, dynamic .editing classCSSSelector doesn't apply. So tipically show/hide UI test are difficult.
97
96
// @ref https://spectrum.chat/testing-library/general/testing-an-accordion~b004a9b1-b104-4eb1-a73b-43c60b1a3630?m=MTU1NDQ4NDIzMTQ5Ng==
98
97
//expect(getByTestId('todo-edit-input')).toBeVisible()
0 commit comments