@@ -103,4 +103,86 @@ describe('.toHaveValue', () => {
103
103
expect ( queryByTestId ( 'radio' ) ) . toHaveValue ( '' )
104
104
} ) . toThrow ( )
105
105
} )
106
+
107
+ test ( 'throws when the expected input value does not match' , ( ) => {
108
+ const { container} = render ( `<input data-testid="one" value="foo" />` )
109
+ const input = container . firstChild
110
+ let errorMessage
111
+ try {
112
+ expect ( input ) . toHaveValue ( 'something else' )
113
+ } catch ( error ) {
114
+ errorMessage = error . message
115
+ }
116
+
117
+ expect ( errorMessage ) . toMatchInlineSnapshot ( `
118
+ "<dim>expect(</><red>element</><dim>).toHaveValue(</><green>something else</><dim>)</>
119
+
120
+ Expected the element to have value:
121
+ <green> something else</>
122
+ Received:
123
+ <red> foo</>"
124
+ ` )
125
+ } )
126
+
127
+ test ( 'throws when using not but the expected input value does match' , ( ) => {
128
+ const { container} = render ( `<input data-testid="one" value="foo" />` )
129
+ const input = container . firstChild
130
+ let errorMessage
131
+
132
+ try {
133
+ expect ( input ) . not . toHaveValue ( 'foo' )
134
+ } catch ( error ) {
135
+ errorMessage = error . message
136
+ }
137
+ expect ( errorMessage ) . toMatchInlineSnapshot ( `
138
+ "<dim>expect(</><red>element</><dim>).not.toHaveValue(</><green>foo</><dim>)</>
139
+
140
+ Expected the element not to have value:
141
+ <green> foo</>
142
+ Received:
143
+ <red> foo</>"
144
+ ` )
145
+ } )
146
+
147
+ test ( 'throws when the form has no a value but a value is expected' , ( ) => {
148
+ const { container} = render ( `<input data-testid="one" />` )
149
+ const input = container . firstChild
150
+ let errorMessage
151
+
152
+ try {
153
+ expect ( input ) . toHaveValue ( )
154
+ } catch ( error ) {
155
+ errorMessage = error . message
156
+ }
157
+ expect ( errorMessage ) . toMatchInlineSnapshot ( `
158
+ "<dim>expect(</><red>element</><dim>).toHaveValue(</><green>expected</><dim>)</>
159
+
160
+ Expected the element to have value:
161
+ <green> (any)</>
162
+ Received:
163
+ "
164
+ ` )
165
+ } )
166
+
167
+ test ( 'throws when the form has a value but none is expected' , ( ) => {
168
+ const { container} = render ( `<input data-testid="one" value="foo" />` )
169
+ const input = container . firstChild
170
+ let errorMessage
171
+
172
+ try {
173
+ expect ( input ) . not . toHaveValue ( )
174
+ } catch ( error ) {
175
+ errorMessage = error . message
176
+ }
177
+ expect ( errorMessage ) . toMatchInlineSnapshot ( `
178
+ "<dim>expect(</><red>element</><dim>).not.toHaveValue(</><green>expected</><dim>)</>
179
+
180
+ Expected the element not to have value:
181
+ <green> (any)</>
182
+ Received:
183
+ <red> foo</>"
184
+ ` )
185
+ } )
106
186
} )
187
+
188
+ /* eslint max-lines-per-function:0 */
0 commit comments