Skip to content

Commit 4052c73

Browse files
committed
feedback.
1 parent 2d4191c commit 4052c73

19 files changed

+496
-510
lines changed

packages/driver/src/cy/commands/actions/focus.ts

Lines changed: 47 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -22,85 +22,85 @@ interface InternalBlurOptions extends Partial<Cypress.BlurOptions> {
2222

2323
export default (Commands, Cypress, cy) => {
2424
return Commands.addAll({ prevSubject: ['element', 'window'] }, {
25-
focus (subject, options: Partial<Cypress.Loggable & Cypress.Timeoutable> = {}) {
25+
focus (subject, userOptions: Partial<Cypress.Loggable & Cypress.Timeoutable> = {}) {
2626
// we should throw errors by default!
2727
// but allow them to be silenced
28-
const _options: InternalFocusOptions = _.defaults({}, options, {
28+
const options: InternalFocusOptions = _.defaults({}, userOptions, {
2929
$el: subject,
3030
error: true,
3131
log: true,
3232
verify: true,
3333
})
3434

35-
const isWin = $dom.isWindow(_options.$el)
35+
const isWin = $dom.isWindow(options.$el)
3636

3737
if (isWin) {
3838
// get this into a jquery object
39-
_options.$el = $dom.wrap(_options.$el)
39+
options.$el = $dom.wrap(options.$el)
4040
}
4141

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,
4646
consoleProps () {
47-
return { 'Applied To': $dom.getElements(_options.$el) }
47+
return { 'Applied To': $dom.getElements(options.$el) }
4848
},
4949
})
5050
}
5151

52-
const el = _options.$el.get(0)
52+
const el = options.$el.get(0)
5353

5454
// the body is not really focusable, but it
5555
// can have focus on initial page load.
5656
// this is instead a noop.
5757
// 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))
6161

6262
// http://www.w3.org/$R/html5/editing.html#specially-focusable
6363
// ensure there is only 1 dom element in the subject
6464
// 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) {
6767
return
6868
}
6969

70-
const node = $dom.stringify(_options.$el)
70+
const node = $dom.stringify(options.$el)
7171

7272
$errUtils.throwErrByPath('focus.invalid_element', {
73-
onFail: _options._log,
73+
onFail: options._log,
7474
args: { node },
7575
})
7676
}
7777

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) {
8080
return
8181
}
8282

8383
$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 },
8686
})
8787
}
8888

8989
cy.fireFocus(el)
9090

9191
const verifyAssertions = () => {
92-
return cy.verifyUpcomingAssertions(_options.$el, _options, {
92+
return cy.verifyUpcomingAssertions(options.$el, options, {
9393
onRetry: verifyAssertions,
9494
})
9595
}
9696

9797
return verifyAssertions()
9898
},
9999

100-
blur (subject, options: Partial<Cypress.BlurOptions> = {}) {
100+
blur (subject, userOptions: Partial<Cypress.BlurOptions> = {}) {
101101
// we should throw errors by default!
102102
// but allow them to be silenced
103-
const _options: InternalBlurOptions = _.defaults({}, options, {
103+
const options: InternalBlurOptions = _.defaults({}, userOptions, {
104104
$el: subject,
105105
$focused: cy.getFocused(),
106106
error: true,
@@ -109,78 +109,78 @@ export default (Commands, Cypress, cy) => {
109109
force: false,
110110
})
111111

112-
const { $focused } = _options
112+
const { $focused } = options
113113

114-
const isWin = $dom.isWindow(_options.$el)
114+
const isWin = $dom.isWindow(options.$el)
115115

116116
if (isWin) {
117117
// get this into a jquery object
118-
_options.$el = $dom.wrap(_options.$el)
118+
options.$el = $dom.wrap(options.$el)
119119
}
120120

121-
const isBody = _options.$el.is('body')
121+
const isBody = options.$el.is('body')
122122

123-
if (_options.log) {
123+
if (options.log) {
124124
// figure out the options which actually change the behavior of clicks
125-
const deltaOptions = $utils.filterOutOptions(_options)
125+
const deltaOptions = $utils.filterOutOptions(options)
126126

127-
_options._log = Cypress.log({
128-
$el: _options.$el,
127+
options._log = Cypress.log({
128+
$el: options.$el,
129129
message: deltaOptions,
130-
timeout: _options.timeout,
130+
timeout: options.timeout,
131131
consoleProps () {
132-
return { 'Applied To': $dom.getElements(_options.$el) }
132+
return { 'Applied To': $dom.getElements(options.$el) }
133133
},
134134
})
135135
}
136136

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) {
139139
return
140140
}
141141

142142
$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 },
145145
})
146146
}
147147

148148
// if we haven't forced the blur, and we don't currently
149149
// 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) {
152152
return
153153
}
154154

155-
$errUtils.throwErrByPath('blur.no_focused_element', { onFail: _options._log })
155+
$errUtils.throwErrByPath('blur.no_focused_element', { onFail: options._log })
156156
}
157157

158158
// if we're currently window dont check for the wrong
159159
// focused element because window will not show up
160160
// as $focused
161-
if (_options.force !== true &&
161+
if (options.force !== true &&
162162
!isWin &&
163163
!isBody &&
164-
_options.$el.get(0) !== $focused.get(0)
164+
options.$el.get(0) !== $focused.get(0)
165165
) {
166-
if (_options.error === false) {
166+
if (options.error === false) {
167167
return
168168
}
169169

170170
const node = $dom.stringify($focused)
171171

172172
$errUtils.throwErrByPath('blur.wrong_focused_element', {
173-
onFail: _options._log,
173+
onFail: options._log,
174174
args: { node },
175175
})
176176
}
177177

178-
const el = _options.$el.get(0)
178+
const el = options.$el.get(0)
179179

180180
cy.fireBlur(el)
181181

182182
const verifyAssertions = () => {
183-
return cy.verifyUpcomingAssertions(_options.$el, _options, {
183+
return cy.verifyUpcomingAssertions(options.$el, options, {
184184
onRetry: verifyAssertions,
185185
})
186186
}

0 commit comments

Comments
 (0)