diff --git a/packages/driver/src/cy/commands/actions/focus.ts b/packages/driver/src/cy/commands/actions/focus.ts index e5bfdf8d3d63..965d16f1b978 100644 --- a/packages/driver/src/cy/commands/actions/focus.ts +++ b/packages/driver/src/cy/commands/actions/focus.ts @@ -22,74 +22,74 @@ interface InternalBlurOptions extends Partial { export default (Commands, Cypress, cy) => { return Commands.addAll({ prevSubject: ['element', 'window'] }, { - focus (subject, options: Partial = {}) { + focus (subject, userOptions: Partial = {}) { // we should throw errors by default! // but allow them to be silenced - const _options: InternalFocusOptions = _.defaults({}, options, { + const options: InternalFocusOptions = _.defaults({}, userOptions, { $el: subject, error: true, log: true, verify: true, }) - const isWin = $dom.isWindow(_options.$el) + const isWin = $dom.isWindow(options.$el) if (isWin) { // get this into a jquery object - _options.$el = $dom.wrap(_options.$el) + options.$el = $dom.wrap(options.$el) } - if (_options.log) { - _options._log = Cypress.log({ - $el: _options.$el, - timeout: _options.timeout, + if (options.log) { + options._log = Cypress.log({ + $el: options.$el, + timeout: options.timeout, consoleProps () { - return { 'Applied To': $dom.getElements(_options.$el) } + return { 'Applied To': $dom.getElements(options.$el) } }, }) } - const el = _options.$el.get(0) + const el = options.$el.get(0) // the body is not really focusable, but it // can have focus on initial page load. // this is instead a noop. // TODO: throw on body instead (breaking change) - const isBody = $dom.isJquery(_options.$el) && - $elements.isElement(_options.$el.get(0)) && - $elements.isBody(_options.$el.get(0)) + const isBody = $dom.isJquery(options.$el) && + $elements.isElement(options.$el.get(0)) && + $elements.isBody(options.$el.get(0)) // http://www.w3.org/$R/html5/editing.html#specially-focusable // ensure there is only 1 dom element in the subject // make sure its allowed to be focusable - if (!(isWin || isBody || $dom.isFocusable(_options.$el))) { - if (_options.error === false) { + if (!(isWin || isBody || $dom.isFocusable(options.$el))) { + if (options.error === false) { return } - const node = $dom.stringify(_options.$el) + const node = $dom.stringify(options.$el) $errUtils.throwErrByPath('focus.invalid_element', { - onFail: _options._log, + onFail: options._log, args: { node }, }) } - if (_options.$el.length && _options.$el.length > 1) { - if (_options.error === false) { + if (options.$el.length && options.$el.length > 1) { + if (options.error === false) { return } $errUtils.throwErrByPath('focus.multiple_elements', { - onFail: _options._log, - args: { num: _options.$el.length }, + onFail: options._log, + args: { num: options.$el.length }, }) } cy.fireFocus(el) const verifyAssertions = () => { - return cy.verifyUpcomingAssertions(_options.$el, _options, { + return cy.verifyUpcomingAssertions(options.$el, options, { onRetry: verifyAssertions, }) } @@ -97,10 +97,10 @@ export default (Commands, Cypress, cy) => { return verifyAssertions() }, - blur (subject, options: Partial = {}) { + blur (subject, userOptions: Partial = {}) { // we should throw errors by default! // but allow them to be silenced - const _options: InternalBlurOptions = _.defaults({}, options, { + const options: InternalBlurOptions = _.defaults({}, userOptions, { $el: subject, $focused: cy.getFocused(), error: true, @@ -109,78 +109,78 @@ export default (Commands, Cypress, cy) => { force: false, }) - const { $focused } = _options + const { $focused } = options - const isWin = $dom.isWindow(_options.$el) + const isWin = $dom.isWindow(options.$el) if (isWin) { // get this into a jquery object - _options.$el = $dom.wrap(_options.$el) + options.$el = $dom.wrap(options.$el) } - const isBody = _options.$el.is('body') + const isBody = options.$el.is('body') - if (_options.log) { + if (options.log) { // figure out the options which actually change the behavior of clicks - const deltaOptions = $utils.filterOutOptions(_options) + const deltaOptions = $utils.filterOutOptions(options) - _options._log = Cypress.log({ - $el: _options.$el, + options._log = Cypress.log({ + $el: options.$el, message: deltaOptions, - timeout: _options.timeout, + timeout: options.timeout, consoleProps () { - return { 'Applied To': $dom.getElements(_options.$el) } + return { 'Applied To': $dom.getElements(options.$el) } }, }) } - if (_options.$el.length && _options.$el.length > 1) { - if (_options.error === false) { + if (options.$el.length && options.$el.length > 1) { + if (options.error === false) { return } $errUtils.throwErrByPath('blur.multiple_elements', { - onFail: _options._log, - args: { num: _options.$el.length }, + onFail: options._log, + args: { num: options.$el.length }, }) } // if we haven't forced the blur, and we don't currently // have a focused element OR we aren't the window or body then error - if (_options.force !== true && !$focused && !isWin && !isBody) { - if (_options.error === false) { + if (options.force !== true && !$focused && !isWin && !isBody) { + if (options.error === false) { return } - $errUtils.throwErrByPath('blur.no_focused_element', { onFail: _options._log }) + $errUtils.throwErrByPath('blur.no_focused_element', { onFail: options._log }) } // if we're currently window dont check for the wrong // focused element because window will not show up // as $focused - if (_options.force !== true && + if (options.force !== true && !isWin && !isBody && - _options.$el.get(0) !== $focused.get(0) + options.$el.get(0) !== $focused.get(0) ) { - if (_options.error === false) { + if (options.error === false) { return } const node = $dom.stringify($focused) $errUtils.throwErrByPath('blur.wrong_focused_element', { - onFail: _options._log, + onFail: options._log, args: { node }, }) } - const el = _options.$el.get(0) + const el = options.$el.get(0) cy.fireBlur(el) const verifyAssertions = () => { - return cy.verifyUpcomingAssertions(_options.$el, _options, { + return cy.verifyUpcomingAssertions(options.$el, options, { onRetry: verifyAssertions, }) } diff --git a/packages/driver/src/cy/commands/actions/scroll.ts b/packages/driver/src/cy/commands/actions/scroll.ts index 9105e490353e..e1bbee118399 100644 --- a/packages/driver/src/cy/commands/actions/scroll.ts +++ b/packages/driver/src/cy/commands/actions/scroll.ts @@ -47,9 +47,9 @@ interface InternalScrollToOptions extends Partial { export default (Commands, Cypress, cy, state) => { Commands.addAll({ prevSubject: 'element' }, { - scrollIntoView (subject, options: Partial = {}) { - if (!_.isObject(options)) { - $errUtils.throwErrByPath('scrollIntoView.invalid_argument', { args: { arg: options } }) + scrollIntoView (subject, userOptions: Partial = {}) { + if (!_.isObject(userOptions)) { + $errUtils.throwErrByPath('scrollIntoView.invalid_argument', { args: { arg: userOptions } }) } // ensure the subject is not window itself @@ -63,7 +63,7 @@ export default (Commands, Cypress, cy, state) => { $errUtils.throwErrByPath('scrollIntoView.multiple_elements', { args: { num: subject.length } }) } - const _options: InternalScrollIntoViewOptions = _.defaults({}, options, { + const options: InternalScrollIntoViewOptions = _.defaults({}, userOptions, { $el: subject, $parent: state('window'), log: true, @@ -73,69 +73,69 @@ export default (Commands, Cypress, cy, state) => { }) // figure out the options which actually change the behavior of clicks - let deltaOptions = $utils.filterOutOptions(_options) + let deltaOptions = $utils.filterOutOptions(options) // here we want to figure out what has to actually // be scrolled to get to this element, cause we need // to scrollTo passing in that element. - _options.$parent = findScrollableParent(_options.$el, state('window')) + options.$parent = findScrollableParent(options.$el, state('window')) let parentIsWin = false - if (_options.$parent === state('window')) { + if (options.$parent === state('window')) { parentIsWin = true // jQuery scrollTo looks for the prop contentWindow // otherwise it'll use the wrong window to scroll :( - _options.$parent.contentWindow = _options.$parent + options.$parent.contentWindow = options.$parent } // if we cannot parse an integer out of duration // which could be 500 or "500", then it's NaN...throw - if (isNaNOrInfinity(_options.duration)) { - $errUtils.throwErrByPath('scrollIntoView.invalid_duration', { args: { duration: _options.duration } }) + if (isNaNOrInfinity(options.duration)) { + $errUtils.throwErrByPath('scrollIntoView.invalid_duration', { args: { duration: options.duration } }) } - if (!((_options.easing === 'swing') || (_options.easing === 'linear'))) { - $errUtils.throwErrByPath('scrollIntoView.invalid_easing', { args: { easing: _options.easing } }) + if (!((options.easing === 'swing') || (options.easing === 'linear'))) { + $errUtils.throwErrByPath('scrollIntoView.invalid_easing', { args: { easing: options.easing } }) } - if (_options.log) { - deltaOptions = $utils.filterOutOptions(_options, { duration: 0, easing: 'swing', offset: { left: 0, top: 0 } }) + if (options.log) { + deltaOptions = $utils.filterOutOptions(options, { duration: 0, easing: 'swing', offset: { left: 0, top: 0 } }) const log = { - $el: _options.$el, + $el: options.$el, message: deltaOptions, - timeout: _options.timeout, + timeout: options.timeout, consoleProps () { const obj = { // merge into consoleProps without mutating it - 'Applied To': $dom.getElements(_options.$el), - 'Scrolled Element': $dom.getElements(_options.$el), + 'Applied To': $dom.getElements(options.$el), + 'Scrolled Element': $dom.getElements(options.$el), } return obj }, } - _options._log = Cypress.log(log) + options._log = Cypress.log(log) } if (!parentIsWin) { // scroll the parent into view first // before attemp - _options.$parent[0].scrollIntoView() + options.$parent[0].scrollIntoView() } const scrollIntoView = () => { return new Promise((resolve, reject) => { // scroll our axes - return $(_options.$parent).scrollTo(_options.$el, { - axis: _options.axis, - easing: _options.easing, - duration: _options.duration, - offset: _options.offset, + return $(options.$parent).scrollTo(options.$el, { + axis: options.axis, + easing: options.easing, + duration: options.duration, + offset: options.offset, done () { - return resolve(_options.$el) + return resolve(options.$el) }, fail () { // its Promise object is rejected @@ -147,7 +147,7 @@ export default (Commands, Cypress, cy, state) => { }, always () { if (parentIsWin) { - delete _options.$parent.contentWindow + delete options.$parent.contentWindow } }, }) @@ -157,7 +157,7 @@ export default (Commands, Cypress, cy, state) => { return scrollIntoView() .then(() => { const verifyAssertions = () => { - return cy.verifyUpcomingAssertions(_options.$el, _options, { + return cy.verifyUpcomingAssertions(options.$el, options, { onRetry: verifyAssertions, }) } @@ -168,9 +168,8 @@ export default (Commands, Cypress, cy, state) => { }) Commands.addAll({ prevSubject: ['optional', 'element', 'window'] }, { - scrollTo (subject, xOrPosition, yOrOptions, options: Partial = {}) { + scrollTo (subject, xOrPosition, yOrOptions, userOptions: Partial = {}) { let x; let y - let userOptions = options // check for undefined or null values if (xOrPosition === undefined || xOrPosition === null) { @@ -271,7 +270,7 @@ export default (Commands, Cypress, cy, state) => { $errUtils.throwErrByPath('scrollTo.multiple_containers', { args: { num: $container.length } }) } - const _options: InternalScrollToOptions = _.defaults({}, userOptions, { + const options: InternalScrollToOptions = _.defaults({}, userOptions, { $el: $container, log: true, duration: 0, @@ -284,28 +283,28 @@ export default (Commands, Cypress, cy, state) => { // if we cannot parse an integer out of duration // which could be 500 or "500", then it's NaN...throw - if (isNaNOrInfinity(_options.duration)) { - $errUtils.throwErrByPath('scrollTo.invalid_duration', { args: { duration: _options.duration } }) + if (isNaNOrInfinity(options.duration)) { + $errUtils.throwErrByPath('scrollTo.invalid_duration', { args: { duration: options.duration } }) } - if (!((_options.easing === 'swing') || (_options.easing === 'linear'))) { - $errUtils.throwErrByPath('scrollTo.invalid_easing', { args: { easing: _options.easing } }) + if (!((options.easing === 'swing') || (options.easing === 'linear'))) { + $errUtils.throwErrByPath('scrollTo.invalid_easing', { args: { easing: options.easing } }) } - if (!_.isBoolean(_options.ensureScrollable)) { - $errUtils.throwErrByPath('scrollTo.invalid_ensureScrollable', { args: { ensureScrollable: _options.ensureScrollable } }) + if (!_.isBoolean(options.ensureScrollable)) { + $errUtils.throwErrByPath('scrollTo.invalid_ensureScrollable', { args: { ensureScrollable: options.ensureScrollable } }) } // if we cannot parse an integer out of y or x // which could be 50 or "50px" or "50%" then // it's NaN/Infinity...throw - if (isNaNOrInfinity(_options.y) || isNaNOrInfinity(_options.x)) { + if (isNaNOrInfinity(options.y) || isNaNOrInfinity(options.x)) { $errUtils.throwErrByPath('scrollTo.invalid_target', { args: { x, y } }) } - if (_options.log) { + if (options.log) { const deltaOptions = $utils.stringify( - $utils.filterOutOptions(_options, { duration: 0, easing: 'swing' }), + $utils.filterOutOptions(options, { duration: 0, easing: 'swing' }), ) const messageArgs: string[] = [] @@ -323,7 +322,7 @@ export default (Commands, Cypress, cy, state) => { const log: Record = { message: messageArgs.join(', '), - timeout: _options.timeout, + timeout: options.timeout, consoleProps () { // merge into consoleProps without mutating it const obj: Record = {} @@ -339,23 +338,23 @@ export default (Commands, Cypress, cy, state) => { obj.Options = deltaOptions } - obj['Scrolled Element'] = $dom.getElements(_options.$el) + obj['Scrolled Element'] = $dom.getElements(options.$el) return obj }, } if (!isWin) { - log.$el = _options.$el + log.$el = options.$el } - _options._log = Cypress.log(log) + options._log = Cypress.log(log) } const ensureScrollability = () => { // Some elements are not scrollable, user may opt out of error checking // https://github.com/cypress-io/cypress/issues/1924 - if (!_options.ensureScrollable) { + if (!options.ensureScrollable) { return } @@ -363,25 +362,25 @@ export default (Commands, Cypress, cy, state) => { // make sure our container can even be scrolled return cy.ensureScrollability($container, 'scrollTo') } catch (err) { - _options.error = err + options.error = err - return cy.retry(ensureScrollability, _options) + return cy.retry(ensureScrollability, options) } } const scrollTo = () => { return new Promise((resolve, reject) => { // scroll our axis - $(_options.$el).scrollTo({ left: x, top: y }, { - axis: _options.axis, - easing: _options.easing, - duration: _options.duration, + $(options.$el).scrollTo({ left: x, top: y }, { + axis: options.axis, + easing: options.easing, + duration: options.duration, // TODO: ensureScrollable option does not exist on jQuery or config/jquery.scrollto.ts. // It can be removed. // @ts-ignore - ensureScrollable: _options.ensureScrollable, + ensureScrollable: options.ensureScrollable, done () { - return resolve(_options.$el) + return resolve(options.$el) }, fail () { // its Promise object is rejected @@ -394,7 +393,7 @@ export default (Commands, Cypress, cy, state) => { }) if (isWin) { - delete _options.$el.contentWindow + delete options.$el.contentWindow } }) } @@ -404,7 +403,7 @@ export default (Commands, Cypress, cy, state) => { .then(scrollTo) .then(() => { const verifyAssertions = () => { - return cy.verifyUpcomingAssertions(_options.$el, _options, { + return cy.verifyUpcomingAssertions(options.$el, options, { onRetry: verifyAssertions, }) } diff --git a/packages/driver/src/cy/commands/actions/select.ts b/packages/driver/src/cy/commands/actions/select.ts index 2fa7ba4d117a..cb5972960206 100644 --- a/packages/driver/src/cy/commands/actions/select.ts +++ b/packages/driver/src/cy/commands/actions/select.ts @@ -16,7 +16,7 @@ interface InternalSelectOptions extends Partial { export default (Commands, Cypress, cy) => { Commands.addAll({ prevSubject: 'element' }, { - select (subject, valueOrTextOrIndex, options: Partial = {}) { + select (subject, valueOrTextOrIndex, userOptions: Partial = {}) { if ( !_.isNumber(valueOrTextOrIndex) && !_.isString(valueOrTextOrIndex) @@ -33,7 +33,7 @@ export default (Commands, Cypress, cy) => { $errUtils.throwErrByPath('select.invalid_array_argument', { args: { value: JSON.stringify(valueOrTextOrIndex) } }) } - const _options: InternalSelectOptions = _.defaults({}, options, { + const options: InternalSelectOptions = _.defaults({}, userOptions, { $el: subject, log: true, force: false, @@ -41,24 +41,24 @@ export default (Commands, Cypress, cy) => { const consoleProps: Record = {} - if (_options.log) { + if (options.log) { // figure out the options which actually change the behavior of clicks - const deltaOptions = $utils.filterOutOptions(_options) + const deltaOptions = $utils.filterOutOptions(options) - _options._log = Cypress.log({ + options._log = Cypress.log({ message: deltaOptions, - $el: _options.$el, - timeout: _options.timeout, + $el: options.$el, + timeout: options.timeout, consoleProps () { // merge into consoleProps without mutating it return _.extend({}, consoleProps, { - 'Applied To': $dom.getElements(_options.$el), + 'Applied To': $dom.getElements(options.$el), 'Options': deltaOptions, }) }, }) - _options._log.snapshot('before', { next: 'after' }) + options._log.snapshot('before', { next: 'after' }) } let node @@ -74,13 +74,13 @@ export default (Commands, Cypress, cy) => { // or texts and clear the previous selections which matches jQuery's // behavior - if (!_options.$el.is('select')) { - node = $dom.stringify(_options.$el) + if (!options.$el.is('select')) { + node = $dom.stringify(options.$el) $errUtils.throwErrByPath('select.invalid_element', { args: { node } }) } - if (_options.$el.length && _options.$el.length > 1) { - $errUtils.throwErrByPath('select.multiple_elements', { args: { num: _options.$el.length } }) + if (options.$el.length && options.$el.length > 1) { + $errUtils.throwErrByPath('select.multiple_elements', { args: { num: options.$el.length } }) } // normalize valueOrTextOrIndex if its not an array @@ -95,7 +95,7 @@ export default (Commands, Cypress, cy) => { return _.isNumber(v) ? v : v.replace(/ /g, '\u00a0') }) - const multiple = _options.$el.prop('multiple') + const multiple = options.$el.prop('multiple') // throw if we're not a multiple select and we've // passed an array of values @@ -107,14 +107,14 @@ export default (Commands, Cypress, cy) => { let notAllUniqueValues // throw if