1
1
import React from 'react' ;
2
- import { shallow } from 'enzyme ' ;
2
+ import { render } from '@testing-library/react ' ;
3
3
4
4
import NativeInput from './NativeInput' ;
5
5
@@ -10,89 +10,91 @@ describe('NativeInput', () => {
10
10
} ;
11
11
12
12
it ( 'renders an input' , ( ) => {
13
- const component = shallow ( < NativeInput { ...defaultProps } /> ) ;
13
+ const { container } = render ( < NativeInput { ...defaultProps } /> ) ;
14
14
15
- const input = component . find ( 'input' ) ;
15
+ const input = container . querySelector ( 'input' ) ;
16
16
17
- expect ( input ) . toHaveLength ( 1 ) ;
17
+ expect ( input ) . toBeInTheDocument ( ) ;
18
18
} ) ;
19
19
20
20
it ( 'applies given aria-label properly' , ( ) => {
21
21
const nativeInputAriaLabel = 'Date' ;
22
22
23
- const component = shallow ( < NativeInput { ...defaultProps } ariaLabel = { nativeInputAriaLabel } /> ) ;
23
+ const { container } = render (
24
+ < NativeInput { ...defaultProps } ariaLabel = { nativeInputAriaLabel } /> ,
25
+ ) ;
24
26
25
- const select = component . find ( 'input' ) ;
27
+ const input = container . querySelector ( 'input' ) ;
26
28
27
- expect ( select . prop ( 'aria-label' ) ) . toBe ( nativeInputAriaLabel ) ;
29
+ expect ( input ) . toHaveAttribute ( 'aria-label' , nativeInputAriaLabel ) ;
28
30
} ) ;
29
31
30
32
it ( 'has proper name defined' , ( ) => {
31
33
const name = 'testName' ;
32
34
33
- const component = shallow ( < NativeInput { ...defaultProps } name = { name } /> ) ;
35
+ const { container } = render ( < NativeInput { ...defaultProps } name = { name } /> ) ;
34
36
35
- const input = component . find ( 'input' ) ;
37
+ const input = container . querySelector ( 'input' ) ;
36
38
37
- expect ( input . prop ( 'name' ) ) . toBe ( name ) ;
39
+ expect ( input ) . toHaveAttribute ( 'name' , name ) ;
38
40
} ) ;
39
41
42
+ // TODO: Investigate why ".000" is added here
40
43
it . each `
41
44
valueType | parsedValue
42
- ${ 'second' } | ${ '2017-09-30T22:17:41' }
45
+ ${ 'second' } | ${ '2017-09-30T22:17:41.000 ' }
43
46
${ 'minute' } | ${ '2017-09-30T22:17' }
44
47
${ 'hour' } | ${ '2017-09-30T22:00' }
45
48
` ( 'displays given value properly if valueType is $valueType' , ( { valueType, parsedValue } ) => {
46
49
const value = new Date ( 2017 , 8 , 30 , 22 , 17 , 41 ) ;
47
50
48
- const component = shallow (
51
+ const { container } = render (
49
52
< NativeInput { ...defaultProps } value = { value } valueType = { valueType } /> ,
50
53
) ;
51
54
52
- const input = component . find ( 'input' ) ;
55
+ const input = container . querySelector ( 'input' ) ;
53
56
54
- expect ( input . prop ( 'value' ) ) . toBe ( parsedValue ) ;
57
+ expect ( input ) . toHaveValue ( parsedValue ) ;
55
58
} ) ;
56
- /* eslint-enable indent */
57
59
58
60
it ( 'does not disable input by default' , ( ) => {
59
- const component = shallow ( < NativeInput { ...defaultProps } /> ) ;
61
+ const { container } = render ( < NativeInput { ...defaultProps } /> ) ;
60
62
61
- const input = component . find ( 'input' ) ;
63
+ const input = container . querySelector ( 'input' ) ;
62
64
63
- expect ( input . prop ( 'disabled' ) ) . toBeFalsy ( ) ;
65
+ expect ( input ) . not . toBeDisabled ( ) ;
64
66
} ) ;
65
67
66
68
it ( 'disables input given disabled flag' , ( ) => {
67
- const component = shallow ( < NativeInput { ...defaultProps } disabled /> ) ;
69
+ const { container } = render ( < NativeInput { ...defaultProps } disabled /> ) ;
68
70
69
- const input = component . find ( 'input' ) ;
71
+ const input = container . querySelector ( 'input' ) ;
70
72
71
- expect ( input . prop ( 'disabled' ) ) . toBeTruthy ( ) ;
73
+ expect ( input ) . toBeDisabled ( ) ;
72
74
} ) ;
73
75
74
76
it ( 'is not required input by default' , ( ) => {
75
- const component = shallow ( < NativeInput { ...defaultProps } /> ) ;
77
+ const { container } = render ( < NativeInput { ...defaultProps } /> ) ;
76
78
77
- const input = component . find ( 'input' ) ;
79
+ const input = container . querySelector ( 'input' ) ;
78
80
79
- expect ( input . prop ( 'required' ) ) . toBeFalsy ( ) ;
81
+ expect ( input ) . not . toBeRequired ( ) ;
80
82
} ) ;
81
83
82
84
it ( 'required input given required flag' , ( ) => {
83
- const component = shallow ( < NativeInput { ...defaultProps } required /> ) ;
85
+ const { container } = render ( < NativeInput { ...defaultProps } required /> ) ;
84
86
85
- const input = component . find ( 'input' ) ;
87
+ const input = container . querySelector ( 'input' ) ;
86
88
87
- expect ( input . prop ( 'required' ) ) . toBeTruthy ( ) ;
89
+ expect ( input ) . toBeRequired ( ) ;
88
90
} ) ;
89
91
90
92
it ( 'has no min by default' , ( ) => {
91
- const component = shallow ( < NativeInput { ...defaultProps } /> ) ;
93
+ const { container } = render ( < NativeInput { ...defaultProps } /> ) ;
92
94
93
- const input = component . find ( 'input' ) ;
95
+ const input = container . querySelector ( 'input' ) ;
94
96
95
- expect ( input . prop ( 'min' ) ) . toBeFalsy ( ) ;
97
+ expect ( input ) . not . toHaveAttribute ( 'min' ) ;
96
98
} ) ;
97
99
98
100
it . each `
@@ -103,17 +105,17 @@ describe('NativeInput', () => {
103
105
` (
104
106
'has proper min for minDate which is a full hour if valueType is $valueType' ,
105
107
( { valueType, parsedMin } ) => {
106
- const component = shallow (
108
+ const { container } = render (
107
109
< NativeInput
108
110
{ ...defaultProps }
109
111
minDate = { new Date ( 2017 , 8 , 30 , 22 , 0 , 0 ) }
110
112
valueType = { valueType }
111
113
/> ,
112
114
) ;
113
115
114
- const input = component . find ( 'input' ) ;
116
+ const input = container . querySelector ( 'input' ) ;
115
117
116
- expect ( input . prop ( 'min' ) ) . toBe ( parsedMin ) ;
118
+ expect ( input ) . toHaveAttribute ( 'min' , parsedMin ) ;
117
119
} ,
118
120
) ;
119
121
@@ -125,26 +127,26 @@ describe('NativeInput', () => {
125
127
` (
126
128
'has proper min for minDate which is not a full hour if valueType is $valueType' ,
127
129
( { valueType, parsedMin } ) => {
128
- const component = shallow (
130
+ const { container } = render (
129
131
< NativeInput
130
132
{ ...defaultProps }
131
133
minDate = { new Date ( 2017 , 8 , 30 , 22 , 17 , 41 ) }
132
134
valueType = { valueType }
133
135
/> ,
134
136
) ;
135
137
136
- const input = component . find ( 'input' ) ;
138
+ const input = container . querySelector ( 'input' ) ;
137
139
138
- expect ( input . prop ( 'min' ) ) . toBe ( parsedMin ) ;
140
+ expect ( input ) . toHaveAttribute ( 'min' , parsedMin ) ;
139
141
} ,
140
142
) ;
141
143
142
144
it ( 'has no max by default' , ( ) => {
143
- const component = shallow ( < NativeInput { ...defaultProps } /> ) ;
145
+ const { container } = render ( < NativeInput { ...defaultProps } /> ) ;
144
146
145
- const input = component . find ( 'input' ) ;
147
+ const input = container . querySelector ( 'input' ) ;
146
148
147
- expect ( input . prop ( 'max' ) ) . toBeFalsy ( ) ;
149
+ expect ( input ) . not . toHaveAttribute ( 'max' ) ;
148
150
} ) ;
149
151
150
152
it . each `
@@ -155,17 +157,17 @@ describe('NativeInput', () => {
155
157
` (
156
158
'has proper max for maxDate which is a full hour if valueType is $valueType' ,
157
159
( { valueType, parsedMax } ) => {
158
- const component = shallow (
160
+ const { container } = render (
159
161
< NativeInput
160
162
{ ...defaultProps }
161
163
maxDate = { new Date ( 2017 , 8 , 30 , 22 , 0 , 0 ) }
162
164
valueType = { valueType }
163
165
/> ,
164
166
) ;
165
167
166
- const input = component . find ( 'input' ) ;
168
+ const input = container . querySelector ( 'input' ) ;
167
169
168
- expect ( input . prop ( 'max' ) ) . toBe ( parsedMax ) ;
170
+ expect ( input ) . toHaveAttribute ( 'max' , parsedMax ) ;
169
171
} ,
170
172
) ;
171
173
@@ -177,17 +179,17 @@ describe('NativeInput', () => {
177
179
` (
178
180
'has proper max for maxDate which is not a full hour if valueType is $valueType' ,
179
181
( { valueType, parsedMax } ) => {
180
- const component = shallow (
182
+ const { container } = render (
181
183
< NativeInput
182
184
{ ...defaultProps }
183
185
maxDate = { new Date ( 2017 , 8 , 30 , 22 , 17 , 41 ) }
184
186
valueType = { valueType }
185
187
/> ,
186
188
) ;
187
189
188
- const input = component . find ( 'input' ) ;
190
+ const input = container . querySelector ( 'input' ) ;
189
191
190
- expect ( input . prop ( 'max' ) ) . toBe ( parsedMax ) ;
192
+ expect ( input ) . toHaveAttribute ( 'max' , parsedMax ) ;
191
193
} ,
192
194
) ;
193
195
} ) ;
0 commit comments