@@ -88,18 +88,15 @@ describe('find* dom-testing-library commands', () => {
88
88
/* Test the behaviour around these queries */
89
89
90
90
it ( 'findByText should handle non-existence' , ( ) => {
91
- cy . findByText ( 'Does Not Exist' )
92
- . should ( 'not.exist' )
91
+ cy . findByText ( 'Does Not Exist' ) . should ( 'not.exist' )
93
92
} )
94
93
95
94
it ( 'findByText should handle eventual existence' , ( ) => {
96
- cy . findByText ( 'Eventually Exists' )
97
- . should ( 'exist' )
95
+ cy . findByText ( 'Eventually Exists' ) . should ( 'exist' )
98
96
} )
99
97
100
98
it ( 'findByText should handle eventual non-existence' , ( ) => {
101
- cy . findByText ( 'Eventually Not exists' )
102
- . should ( 'not.exist' )
99
+ cy . findByText ( 'Eventually Not exists' ) . should ( 'not.exist' )
103
100
} )
104
101
105
102
it ( "findByText with should('not.exist')" , ( ) => {
@@ -111,7 +108,7 @@ describe('find* dom-testing-library commands', () => {
111
108
112
109
it ( 'findByText with a previous subject' , ( ) => {
113
110
cy . get ( '#nested' )
114
- . findByText ( 'Button Text 1' , { fallbackRetryWithoutPreviousSubject : false } )
111
+ . findByText ( 'Button Text 1' , { fallbackRetryWithoutPreviousSubject : false } )
115
112
. should ( 'not.exist' )
116
113
cy . get ( '#nested' )
117
114
. findByText ( 'Button Text 2' )
@@ -170,8 +167,7 @@ describe('find* dom-testing-library commands', () => {
170
167
expect ( err . message ) . to . contain ( errorMessage )
171
168
} )
172
169
173
- cy . findByText ( 'Button Text 1' , { timeout : 100 } )
174
- . should ( 'not.exist' )
170
+ cy . findByText ( 'Button Text 1' , { timeout : 100 } ) . should ( 'not.exist' )
175
171
} )
176
172
177
173
it ( 'findByLabelText should forward useful error messages from @testing-library/dom' , ( ) => {
@@ -196,11 +192,14 @@ describe('find* dom-testing-library commands', () => {
196
192
cy . window ( )
197
193
. findByText ( 'Button Text 1' )
198
194
. should ( 'exist' )
195
+ cy . location ( )
196
+ . findByText ( 'Button Text 1' )
197
+ . should ( 'exist' )
199
198
} )
200
199
201
200
it ( 'findByText should show as a parent command if it starts a chain' , ( ) => {
202
201
const assertLog = ( attrs , log ) => {
203
- if ( log . get ( 'name' ) === 'findByText' ) {
202
+ if ( log . get ( 'name' ) === 'findByText' ) {
204
203
expect ( log . get ( 'type' ) ) . to . equal ( 'parent' )
205
204
cy . off ( 'log:added' , assertLog )
206
205
}
@@ -211,14 +210,25 @@ describe('find* dom-testing-library commands', () => {
211
210
212
211
it ( 'findByText should show as a child command if it continues a chain' , ( ) => {
213
212
const assertLog = ( attrs , log ) => {
214
- if ( log . get ( 'name' ) === 'findByText' ) {
213
+ if ( log . get ( 'name' ) === 'findByText' ) {
215
214
expect ( log . get ( 'type' ) ) . to . equal ( 'child' )
216
215
cy . off ( 'log:added' , assertLog )
217
216
}
218
217
}
219
218
cy . on ( 'log:added' , assertLog )
220
219
cy . get ( 'body' ) . findByText ( 'Button Text 1' )
221
220
} )
221
+
222
+ it ( 'should chain findBy* with subject different of document, element or window' , ( ) => {
223
+ cy . wrap ( true )
224
+ . should ( 'be.true' )
225
+ . findByText ( 'Error message' )
226
+ . findByLabelText ( / R e q u i r e d / i)
227
+ . type ( 'something' )
228
+ . findByText ( 'Submit' )
229
+ . queryByText ( 'Error message' )
230
+ . should ( 'not.be.visible' )
231
+ } )
222
232
} )
223
233
224
234
/* global cy */
0 commit comments