@@ -22,85 +22,85 @@ interface InternalBlurOptions extends Partial<Cypress.BlurOptions> {
22
22
23
23
export default ( Commands , Cypress , cy ) => {
24
24
return Commands . addAll ( { prevSubject : [ 'element' , 'window' ] } , {
25
- focus ( subject , options : Partial < Cypress . Loggable & Cypress . Timeoutable > = { } ) {
25
+ focus ( subject , userOptions : Partial < Cypress . Loggable & Cypress . Timeoutable > = { } ) {
26
26
// we should throw errors by default!
27
27
// but allow them to be silenced
28
- const _options : InternalFocusOptions = _ . defaults ( { } , options , {
28
+ const options : InternalFocusOptions = _ . defaults ( { } , userOptions , {
29
29
$el : subject ,
30
30
error : true ,
31
31
log : true ,
32
32
verify : true ,
33
33
} )
34
34
35
- const isWin = $dom . isWindow ( _options . $el )
35
+ const isWin = $dom . isWindow ( options . $el )
36
36
37
37
if ( isWin ) {
38
38
// get this into a jquery object
39
- _options . $el = $dom . wrap ( _options . $el )
39
+ options . $el = $dom . wrap ( options . $el )
40
40
}
41
41
42
- if ( _options . log ) {
43
- _options . _log = Cypress . log ( {
44
- $el : _options . $el ,
45
- timeout : _options . timeout ,
42
+ if ( options . log ) {
43
+ options . _log = Cypress . log ( {
44
+ $el : options . $el ,
45
+ timeout : options . timeout ,
46
46
consoleProps ( ) {
47
- return { 'Applied To' : $dom . getElements ( _options . $el ) }
47
+ return { 'Applied To' : $dom . getElements ( options . $el ) }
48
48
} ,
49
49
} )
50
50
}
51
51
52
- const el = _options . $el . get ( 0 )
52
+ const el = options . $el . get ( 0 )
53
53
54
54
// the body is not really focusable, but it
55
55
// can have focus on initial page load.
56
56
// this is instead a noop.
57
57
// TODO: throw on body instead (breaking change)
58
- const isBody = $dom . isJquery ( _options . $el ) &&
59
- $elements . isElement ( _options . $el . get ( 0 ) ) &&
60
- $elements . isBody ( _options . $el . get ( 0 ) )
58
+ const isBody = $dom . isJquery ( options . $el ) &&
59
+ $elements . isElement ( options . $el . get ( 0 ) ) &&
60
+ $elements . isBody ( options . $el . get ( 0 ) )
61
61
62
62
// http://www.w3.org/$R/html5/editing.html#specially-focusable
63
63
// ensure there is only 1 dom element in the subject
64
64
// make sure its allowed to be focusable
65
- if ( ! ( isWin || isBody || $dom . isFocusable ( _options . $el ) ) ) {
66
- if ( _options . error === false ) {
65
+ if ( ! ( isWin || isBody || $dom . isFocusable ( options . $el ) ) ) {
66
+ if ( options . error === false ) {
67
67
return
68
68
}
69
69
70
- const node = $dom . stringify ( _options . $el )
70
+ const node = $dom . stringify ( options . $el )
71
71
72
72
$errUtils . throwErrByPath ( 'focus.invalid_element' , {
73
- onFail : _options . _log ,
73
+ onFail : options . _log ,
74
74
args : { node } ,
75
75
} )
76
76
}
77
77
78
- if ( _options . $el . length && _options . $el . length > 1 ) {
79
- if ( _options . error === false ) {
78
+ if ( options . $el . length && options . $el . length > 1 ) {
79
+ if ( options . error === false ) {
80
80
return
81
81
}
82
82
83
83
$errUtils . throwErrByPath ( 'focus.multiple_elements' , {
84
- onFail : _options . _log ,
85
- args : { num : _options . $el . length } ,
84
+ onFail : options . _log ,
85
+ args : { num : options . $el . length } ,
86
86
} )
87
87
}
88
88
89
89
cy . fireFocus ( el )
90
90
91
91
const verifyAssertions = ( ) => {
92
- return cy . verifyUpcomingAssertions ( _options . $el , _options , {
92
+ return cy . verifyUpcomingAssertions ( options . $el , options , {
93
93
onRetry : verifyAssertions ,
94
94
} )
95
95
}
96
96
97
97
return verifyAssertions ( )
98
98
} ,
99
99
100
- blur ( subject , options : Partial < Cypress . BlurOptions > = { } ) {
100
+ blur ( subject , userOptions : Partial < Cypress . BlurOptions > = { } ) {
101
101
// we should throw errors by default!
102
102
// but allow them to be silenced
103
- const _options : InternalBlurOptions = _ . defaults ( { } , options , {
103
+ const options : InternalBlurOptions = _ . defaults ( { } , userOptions , {
104
104
$el : subject ,
105
105
$focused : cy . getFocused ( ) ,
106
106
error : true ,
@@ -109,78 +109,78 @@ export default (Commands, Cypress, cy) => {
109
109
force : false ,
110
110
} )
111
111
112
- const { $focused } = _options
112
+ const { $focused } = options
113
113
114
- const isWin = $dom . isWindow ( _options . $el )
114
+ const isWin = $dom . isWindow ( options . $el )
115
115
116
116
if ( isWin ) {
117
117
// get this into a jquery object
118
- _options . $el = $dom . wrap ( _options . $el )
118
+ options . $el = $dom . wrap ( options . $el )
119
119
}
120
120
121
- const isBody = _options . $el . is ( 'body' )
121
+ const isBody = options . $el . is ( 'body' )
122
122
123
- if ( _options . log ) {
123
+ if ( options . log ) {
124
124
// figure out the options which actually change the behavior of clicks
125
- const deltaOptions = $utils . filterOutOptions ( _options )
125
+ const deltaOptions = $utils . filterOutOptions ( options )
126
126
127
- _options . _log = Cypress . log ( {
128
- $el : _options . $el ,
127
+ options . _log = Cypress . log ( {
128
+ $el : options . $el ,
129
129
message : deltaOptions ,
130
- timeout : _options . timeout ,
130
+ timeout : options . timeout ,
131
131
consoleProps ( ) {
132
- return { 'Applied To' : $dom . getElements ( _options . $el ) }
132
+ return { 'Applied To' : $dom . getElements ( options . $el ) }
133
133
} ,
134
134
} )
135
135
}
136
136
137
- if ( _options . $el . length && _options . $el . length > 1 ) {
138
- if ( _options . error === false ) {
137
+ if ( options . $el . length && options . $el . length > 1 ) {
138
+ if ( options . error === false ) {
139
139
return
140
140
}
141
141
142
142
$errUtils . throwErrByPath ( 'blur.multiple_elements' , {
143
- onFail : _options . _log ,
144
- args : { num : _options . $el . length } ,
143
+ onFail : options . _log ,
144
+ args : { num : options . $el . length } ,
145
145
} )
146
146
}
147
147
148
148
// if we haven't forced the blur, and we don't currently
149
149
// have a focused element OR we aren't the window or body then error
150
- if ( _options . force !== true && ! $focused && ! isWin && ! isBody ) {
151
- if ( _options . error === false ) {
150
+ if ( options . force !== true && ! $focused && ! isWin && ! isBody ) {
151
+ if ( options . error === false ) {
152
152
return
153
153
}
154
154
155
- $errUtils . throwErrByPath ( 'blur.no_focused_element' , { onFail : _options . _log } )
155
+ $errUtils . throwErrByPath ( 'blur.no_focused_element' , { onFail : options . _log } )
156
156
}
157
157
158
158
// if we're currently window dont check for the wrong
159
159
// focused element because window will not show up
160
160
// as $focused
161
- if ( _options . force !== true &&
161
+ if ( options . force !== true &&
162
162
! isWin &&
163
163
! isBody &&
164
- _options . $el . get ( 0 ) !== $focused . get ( 0 )
164
+ options . $el . get ( 0 ) !== $focused . get ( 0 )
165
165
) {
166
- if ( _options . error === false ) {
166
+ if ( options . error === false ) {
167
167
return
168
168
}
169
169
170
170
const node = $dom . stringify ( $focused )
171
171
172
172
$errUtils . throwErrByPath ( 'blur.wrong_focused_element' , {
173
- onFail : _options . _log ,
173
+ onFail : options . _log ,
174
174
args : { node } ,
175
175
} )
176
176
}
177
177
178
- const el = _options . $el . get ( 0 )
178
+ const el = options . $el . get ( 0 )
179
179
180
180
cy . fireBlur ( el )
181
181
182
182
const verifyAssertions = ( ) => {
183
- return cy . verifyUpcomingAssertions ( _options . $el , _options , {
183
+ return cy . verifyUpcomingAssertions ( options . $el , options , {
184
184
onRetry : verifyAssertions ,
185
185
} )
186
186
}
0 commit comments