From 1e7b5966989a94429a4c802b4e4210596399e2d2 Mon Sep 17 00:00:00 2001 From: Jennifer Shehane Date: Mon, 24 Feb 2025 13:21:53 -0500 Subject: [PATCH] misc: Add some missing types + Convert js driver/query tests to ts (#31154) * misc: Add some missing types + Convert js driver/query tests to ts * changelog entry * reuse partial * Update cli/CHANGELOG.md * Update call to querySelector to assign an identifier when checking for null --- cli/CHANGELOG.md | 1 + cli/types/cypress.d.ts | 15 +- .../component/{spec.cy.js => spec.cy.ts} | 12 +- .../querying/{focused.cy.js => focused.cy.ts} | 2 +- .../{querying.cy.js => querying.cy.ts} | 178 +++++++++--------- .../querying/{root.cy.js => root.cy.ts} | 1 + .../{shadow_dom.cy.js => shadow_dom.cy.ts} | 1 + .../querying/{within.cy.js => within.cy.ts} | 12 +- .../src/cy/commands/querying/querying.ts | 6 +- .../driver/src/cy/commands/querying/root.ts | 3 +- .../driver/types/internal-types-lite.d.ts | 2 +- 11 files changed, 127 insertions(+), 106 deletions(-) rename packages/driver/cypress/component/{spec.cy.js => spec.cy.ts} (83%) rename packages/driver/cypress/e2e/commands/querying/{focused.cy.js => focused.cy.ts} (99%) rename packages/driver/cypress/e2e/commands/querying/{querying.cy.js => querying.cy.ts} (93%) rename packages/driver/cypress/e2e/commands/querying/{root.cy.js => root.cy.ts} (98%) rename packages/driver/cypress/e2e/commands/querying/{shadow_dom.cy.js => shadow_dom.cy.ts} (99%) rename packages/driver/cypress/e2e/commands/querying/{within.cy.js => within.cy.ts} (96%) diff --git a/cli/CHANGELOG.md b/cli/CHANGELOG.md index 0f9a99cc4a50..75c237dd6e6d 100644 --- a/cli/CHANGELOG.md +++ b/cli/CHANGELOG.md @@ -11,6 +11,7 @@ _Released 2/25/2025 (PENDING)_ - Viewport width, height, and scale now display in a badge above the application under test. The dropdown describing how to set viewport height and width has been removed from the UI. Additionally, component tests now show a notice about URL navigation being disabled in component tests. Addresses [#30999](https://github.com/cypress-io/cypress/issues/30999). Addressed in [#31119](https://github.com/cypress-io/cypress/pull/31119). - Updated types around `.readFile()` and `.scrollTo()` arguments and `Cypress.dom` methods. Addressed in [#31055](https://github.com/cypress-io/cypress/pull/31055). +- Updated types around `.shadow()` and `.root()` options. Addressed in [#31154](https://github.com/cypress-io/cypress/pull/31154). **Dependency Updates:** diff --git a/cli/types/cypress.d.ts b/cli/types/cypress.d.ts index a234f9b2fc24..9c800f56adbe 100644 --- a/cli/types/cypress.d.ts +++ b/cli/types/cypress.d.ts @@ -1898,7 +1898,7 @@ declare namespace Cypress { * * @see https://on.cypress.io/root */ - root(options?: Partial): Chainable> // can't do better typing unless we ignore the `.within()` case + root(options?: Partial): Chainable> // can't do better typing unless we ignore the `.within()` case /** * Take a screenshot of the application under test and the Cypress Command Log. @@ -1980,6 +1980,18 @@ declare namespace Cypress { */ shadow(): Chainable + /** + * Traverse into an element's shadow root. + * + * @example + * cy.get('my-component') + * .shadow({ timeout: 10000, log: false }) + * .find('.my-button') + * .click() + * @see https://on.cypress.io/shadow + */ + shadow(options?: Partial): Chainable + /** * Create an assertion. Assertions are automatically retried until they pass or time out. * @@ -2732,6 +2744,7 @@ declare namespace Cypress { interface CheckClearOptions extends Loggable, Timeoutable, ActionableOptions { } + interface LogTimeoutOptions extends Loggable, Timeoutable { } /** * Object to change the default behavior of .click(). */ diff --git a/packages/driver/cypress/component/spec.cy.js b/packages/driver/cypress/component/spec.cy.ts similarity index 83% rename from packages/driver/cypress/component/spec.cy.js rename to packages/driver/cypress/component/spec.cy.ts index dd75b0c62313..2c34b76336cc 100644 --- a/packages/driver/cypress/component/spec.cy.js +++ b/packages/driver/cypress/component/spec.cy.ts @@ -1,7 +1,6 @@ const { sinon } = Cypress describe('component testing', () => { - /** @type {Cypress.Agent} */ let uncaughtExceptionStub before(() => { @@ -16,7 +15,11 @@ describe('component testing', () => { beforeEach(() => { uncaughtExceptionStub.resetHistory() - document.querySelector('[data-cy-root]').innerHTML = '' + const root = document.querySelector('[data-cy-root]') + + if (root) { + root.innerHTML = '' + } }) it('fails and shows an error', () => { @@ -28,7 +31,7 @@ describe('component testing', () => { throw new Error('An error!') }) - document.querySelector('[data-cy-root]').appendChild($el) + document.querySelector('[data-cy-root]')?.appendChild($el) cy.get('button').click().then(() => { expect(uncaughtExceptionStub).to.have.been.calledOnceWithExactly(null) expect(Cypress.log).to.be.calledWithMatch(sinon.match({ 'message': `Error: An error!`, name: 'uncaught exception' })) @@ -40,11 +43,12 @@ describe('component testing', () => { const $el = document.createElement('button') $el.innerText = `Don't click it!` + // @ts-expect-error - testing an error state $el.addEventListener('click', new Promise((_, reject) => { reject('Promise rejected with a string!') })) - document.querySelector('[data-cy-root]').appendChild($el) + document.querySelector('[data-cy-root]')?.appendChild($el) cy.get('button').click().then(() => { expect(uncaughtExceptionStub).to.have.been.calledOnceWithExactly(null) expect(Cypress.log).to.be.calledWithMatch(sinon.match({ 'message': `Error: "Promise rejected with a string!"`, name: 'uncaught exception' })) diff --git a/packages/driver/cypress/e2e/commands/querying/focused.cy.js b/packages/driver/cypress/e2e/commands/querying/focused.cy.ts similarity index 99% rename from packages/driver/cypress/e2e/commands/querying/focused.cy.js rename to packages/driver/cypress/e2e/commands/querying/focused.cy.ts index 64d4391e87a0..3c2c612f017c 100644 --- a/packages/driver/cypress/e2e/commands/querying/focused.cy.js +++ b/packages/driver/cypress/e2e/commands/querying/focused.cy.ts @@ -1,4 +1,4 @@ -const { assertLogLength } = require('../../../support/utils') +import { assertLogLength } from '../../../support/utils' const { _ } = Cypress diff --git a/packages/driver/cypress/e2e/commands/querying/querying.cy.js b/packages/driver/cypress/e2e/commands/querying/querying.cy.ts similarity index 93% rename from packages/driver/cypress/e2e/commands/querying/querying.cy.js rename to packages/driver/cypress/e2e/commands/querying/querying.cy.ts index 6b4c751be2c6..f172725ea3fc 100644 --- a/packages/driver/cypress/e2e/commands/querying/querying.cy.js +++ b/packages/driver/cypress/e2e/commands/querying/querying.cy.ts @@ -1,4 +1,4 @@ -const { assertLogLength } = require('../../../support/utils') +import { assertLogLength } from '../../../support/utils' const { _, $, Promise } = Cypress @@ -22,56 +22,16 @@ describe('src/cy/commands/querying', () => { const options = { timeout: {} } const getErrMsgForTimeout = (timeout) => `\`cy.get()\` only accepts a \`number\` for its \`timeout\` option. You passed: \`${timeout}\`` - it('timeout passed as plain object {}', (done) => { - cy.get('#some-el', options) - cy.on('fail', (err) => { - expect(err.message).to.eq(getErrMsgForTimeout(options.timeout)) - done() - }) - }) - - it('timeout passed as some string', (done) => { - options.timeout = 'abc' - cy.get('#some-el', options) - cy.on('fail', (err) => { - expect(err.message).to.eq(getErrMsgForTimeout(options.timeout)) - done() - }) - }) - - it('timeout passed as null', (done) => { - options.timeout = null - cy.get('#some-el', options) - cy.on('fail', (err) => { - expect(err.message).to.eq(getErrMsgForTimeout(options.timeout)) - done() - }) - }) - - it('timeout passed as NaN', (done) => { - options.timeout = NaN - cy.get('#some-el', options) - cy.on('fail', (err) => { - expect(err.message).to.eq(getErrMsgForTimeout(options.timeout)) - done() - }) - }) - - it('timeout passed as Boolean', (done) => { - options.timeout = false - cy.get('#some-el', options) - cy.on('fail', (err) => { - expect(err.message).to.eq(getErrMsgForTimeout(options.timeout)) - done() - }) - }) - - it('timeout passed as array', (done) => { - options.timeout = [] - cy.get('#some-el', options) - cy.on('fail', (err) => { - expect(err.message).to.eq(getErrMsgForTimeout(options.timeout)) - done() + _.each([{}, 'abc', null, NaN, false, []], (value) => { + it(`timeout throws if passed anything other invalid arg, such as: ${value}`, (done) => { + // @ts-expect-error - testing invalid timeout value + options.timeout = value + // @ts-expect-error - testing invalid timeout value + cy.get('#some-el', options) + cy.on('fail', (err) => { + expect(err.message).to.eq(getErrMsgForTimeout(options.timeout)) + done() + }) }) }) }) @@ -255,13 +215,15 @@ describe('src/cy/commands/querying', () => { let button = null const retry = _.after(3, () => { + // @ts-expect-error TODO: Figure out types for this button = cy.$$('#button').hide() }) cy.on('command:retry', retry) cy.get('#button').should('not.be.visible').then(($button) => { - expect($button.get(0)).to.eq(button.get(0)) + // @ts-expect-error TODO: Figure out types for this + expect($button.get(0)).to.eq(button?.get(0)) }) }) }) @@ -616,7 +578,7 @@ describe('src/cy/commands/querying', () => { }) it('can get alias with logging off', { protocolEnabled: true }, () => { - const logs = [] + const logs: any = [] let hiddenLog cy.on('log:added', (attrs, log) => { @@ -663,7 +625,7 @@ describe('src/cy/commands/querying', () => { .window().then({ timeout: 2000 }, (win) => { return win.$.get('/users') }).wait('@getUsers').get('@getUsers').then((xhr) => { - expect(xhr.response.url).to.include('/users') + expect((xhr as unknown as XMLHttpRequest).response.url).to.include('/users') }) }) @@ -675,7 +637,7 @@ describe('src/cy/commands/querying', () => { }) cy.wait('@get.users').get('@get.users').then((xhr) => { - expect(xhr.response.url).to.include('/users') + expect((xhr as unknown as XMLHttpRequest).response.url).to.include('/users') }) }) @@ -698,10 +660,12 @@ describe('src/cy/commands/querying', () => { win.$.get('/users', { num: 2 }), ]) }).wait('@getUsers').wait('@getUsers').get('@getUsers.all').then((xhrs) => { - expect(xhrs).to.be.an('array') - expect(xhrs[0].response.url).to.include('/users?num=1') + const xhrsArray = xhrs as unknown as XMLHttpRequest + + expect(xhrsArray).to.be.an('array') + expect(xhrsArray[0].response.url).to.include('/users?num=1') - expect(xhrs[1].response.url).to.include('/users?num=2') + expect(xhrsArray[1].response.url).to.include('/users?num=2') }) }) @@ -716,10 +680,11 @@ describe('src/cy/commands/querying', () => { }) cy.wait('@get.users').wait('@get.users').get('@get.users.all').then((xhrs) => { - expect(xhrs).to.be.an('array') - expect(xhrs[0].response.url).to.include('/users?num=1') + const xhrsArray = xhrs as unknown as XMLHttpRequest - expect(xhrs[1].response.url).to.include('/users?num=2') + expect(xhrsArray).to.be.an('array') + expect(xhrsArray[0].response.url).to.include('/users?num=1') + expect(xhrsArray[1].response.url).to.include('/users?num=2') }) }) @@ -733,7 +698,7 @@ describe('src/cy/commands/querying', () => { win.$.get('/users', { num: 2 }), ]) }).wait('@getUsers').wait('@getUsers').get('@getUsers.1').then((xhr1) => { - expect(xhr1.response.url).to.include('/users?num=1') + expect((xhr1 as unknown as XMLHttpRequest).response.url).to.include('/users?num=1') }) }) @@ -746,8 +711,11 @@ describe('src/cy/commands/querying', () => { win.$.get('/users', { num: 1 }), win.$.get('/users', { num: 2 }), ]) - }).wait('@getUsers').wait('@getUsers').get('@getUsers.2').then((xhr2) => { - expect(xhr2.response.url).to.include('/users?num=2') + }) + .wait('@getUsers') + .wait('@getUsers') + .get('@getUsers.2').then((xhr2) => { + expect((xhr2 as unknown as XMLHttpRequest).response.url).to.include('/users?num=2') }) }) @@ -762,7 +730,7 @@ describe('src/cy/commands/querying', () => { }) cy.wait('@get.users').wait('@get.users').get('@get.users.2').then((xhr2) => { - expect(xhr2.response.url).to.include('/users?num=2') + expect((xhr2 as unknown as XMLHttpRequest).response.url).to.include('/users?num=2') }) }) @@ -1059,6 +1027,7 @@ describe('src/cy/commands/querying', () => { done() }) + // @ts-expect-error - we are testing invalid input cy.get('foobar', value) }) }) @@ -1114,8 +1083,7 @@ describe('src/cy/commands/querying', () => { it('finds the nearest element by :contains selector', () => { cy.contains('li 0').then(($el) => { - expect($el.length).to.eq(1) - + expect(($el as unknown as JQuery)?.length).to.eq(1) expect($el).to.match('li') }) }) @@ -1136,7 +1104,9 @@ describe('src/cy/commands/querying', () => { }) cy.contains('Quality Control').then(($span) => { - expect($span.get(0)).to.eq(span.get(0)) + const el = $span?.[0] as unknown as HTMLSpanElement + + expect(el).to.eq(span.get(0)) }) }) @@ -1144,8 +1114,10 @@ describe('src/cy/commands/querying', () => { const span = cy.$$('#click-me a span') cy.get('#click-me a').contains('click').then(($span) => { + const el = $span?.[0] as unknown as HTMLSpanElement + expect($span.length).to.eq(1) - expect($span.get(0)).to.eq(span.get(0)) + expect(el).to.eq(span.get(0)) }) }) @@ -1165,7 +1137,7 @@ describe('src/cy/commands/querying', () => { it('can find input type=submits by value', () => { cy.contains('input contains submit').then(($el) => { - expect($el.length).to.eq(1) + expect(($el as unknown as JQuery)?.length).to.eq(1) expect($el).to.match('input[type=submit]') }) }) @@ -1173,14 +1145,14 @@ describe('src/cy/commands/querying', () => { // https://github.com/cypress-io/cypress/issues/21166 it('can find input type=submits by Regex', () => { cy.contains(/input contains submit/).then(($el) => { - expect($el.length).to.eq(1) + expect(($el as unknown as JQuery)?.length).to.eq(1) expect($el).to.match('input[type=submit]') }) }) it('has an optional filter argument', () => { cy.contains('ul', 'li 0').then(($el) => { - expect($el.length).to.eq(1) + expect(($el as unknown as JQuery)?.length).to.eq(1) expect($el).to.match('ul') }) }) @@ -1195,13 +1167,12 @@ describe('src/cy/commands/querying', () => { it('searches all els in comma separated filter', () => { cy.contains('a,button', 'Naruto').then(($el) => { - expect($el.length).to.eq(1) + expect(($el as unknown as JQuery)?.length).to.eq(1) expect($el).to.match('a') }) cy.contains('a,button', 'Boruto').then(($el) => { - expect($el.length).to.eq(1) - + expect(($el as unknown as JQuery)?.length).to.eq(1) expect($el).to.match('button') }) }) @@ -1211,16 +1182,16 @@ describe('src/cy/commands/querying', () => { const bText = 'Boruto' cy.contains('a, button', aText).then(($el) => { - expect($el.length).to.eq(1) + $el as unknown as JQuery + expect($el?.length).to.eq(1) expect($el).to.match('a') - expect($el.text()).to.eq(aText) }) cy.contains('a, button', bText).then(($el) => { - expect($el.length).to.eq(1) + $el as unknown as JQuery + expect($el?.length).to.eq(1) expect($el).to.match('button') - expect($el.text()).to.eq(bText) }) }) @@ -1229,7 +1200,9 @@ describe('src/cy/commands/querying', () => { const input = cy.$$('#input-type-submit input') cy.contains('click me').then(($input) => { - expect($input.get(0)).to.eq(input.get(0)) + const el = $input?.[0] as unknown as HTMLInputElement + + expect(el).to.eq(input.get(0)) }) }) @@ -1237,14 +1210,15 @@ describe('src/cy/commands/querying', () => { const button = cy.$$('#button-inside-a button') cy.contains('click button').then(($btn) => { - expect($btn.get(0)).to.eq(button.get(0)) + const btn = $btn?.[0] as unknown as HTMLButtonElement + + expect(btn).to.eq(button.get(0)) }) }) it('favors anchors next', () => { cy.contains('Home Page').then(($el) => { - expect($el.length).to.eq(1) - + expect(($el as unknown as JQuery)?.length).to.eq(1) expect($el).to.match('a') }) }) @@ -1271,7 +1245,9 @@ describe('src/cy/commands/querying', () => { cy.on('command:retry', retry) cy.contains('brand new content').then(($span) => { - expect($span.get(0)).to.eq(span.get(0)) + const el = $span?.[0] as unknown as HTMLSpanElement + + expect(el).to.eq(span.get(0)) }) }) @@ -1286,9 +1262,11 @@ describe('src/cy/commands/querying', () => { const item = cy.$$('#upper .item') cy.contains('New York').then(($item) => { + const el = $item?.[0] as unknown as HTMLElement + expect($item).to.be.ok - expect($item.get(0)).to.eq(item.get(0)) + expect(el).to.eq(item.get(0)) }) }) @@ -1389,7 +1367,9 @@ describe('src/cy/commands/querying', () => { const span = cy.$$('#not-hidden').hide() cy.contains('span', 'my hidden content').should('not.be.visible').then(($span) => { - expect($span.get(0)).to.eq(span.get(0)) + const el = $span?.[0] as unknown as HTMLElement + + expect(el).to.eq(span.get(0)) }) }) @@ -1409,7 +1389,9 @@ space cy.get('#whitespace1').contains('White space') cy.contains('White space').then(($btn) => { - expect($btn.get(0)).to.eq(btn.get(0)) + const button = $btn?.[0] as unknown as HTMLButtonElement + + expect(button).to.eq(btn.get(0)) }) }) @@ -1423,7 +1405,9 @@ space cy.get('#whitespace2').contains('White space') cy.contains('White space').then(($btn) => { - expect($btn.get(0)).to.eq(btn.get(0)) + const button = $btn?.[0] as unknown as HTMLButtonElement + + expect(button).to.eq(btn.get(0)) }) }) @@ -1436,7 +1420,9 @@ White space cy.get('#whitespace3').contains('White space') cy.contains('White space').then(($btn) => { - expect($btn.get(0)).to.eq(btn.get(0)) + const button = $btn?.[0] as unknown as HTMLButtonElement + + expect(button).to.eq(btn.get(0)) }) }) @@ -1449,7 +1435,9 @@ White space cy.get('#whitespace4').contains('White space') cy.contains(/White space/).then(($btn) => { - expect($btn.get(0)).to.eq(btn.get(0)) + const button = $btn?.[0] as unknown as HTMLButtonElement + + expect(button).to.eq(btn.get(0)) }) }) @@ -1470,7 +1458,9 @@ space cy.get('#whitespace6').contains('White space') cy.contains('White space').then(($btn) => { - expect($btn.get(0)).to.eq(btn.get(0)) + const button = $btn?.[0] as unknown as HTMLButtonElement + + expect(button).to.eq(btn.get(0)) }) }) }) @@ -1678,7 +1668,9 @@ space const span = $(`special char ${char} content`).appendTo(cy.$$('body')) cy.contains('span', new RegExp(_.escapeRegExp(char))).then(($span) => { - expect($span.get(0)).to.eq(span.get(0)) + const el = $span?.[0] as unknown as HTMLElement + + expect(el).to.eq(span.get(0)) }) }) }) @@ -1822,6 +1814,7 @@ space done() }) + // @ts-expect-error - testing invalid argument cy.contains(val) }) }) @@ -1845,6 +1838,7 @@ space done() }) + // @ts-expect-error - testing invalid argument cy.contains(undefined) }) diff --git a/packages/driver/cypress/e2e/commands/querying/root.cy.js b/packages/driver/cypress/e2e/commands/querying/root.cy.ts similarity index 98% rename from packages/driver/cypress/e2e/commands/querying/root.cy.js rename to packages/driver/cypress/e2e/commands/querying/root.cy.ts index 7338730413d6..550ac256b48c 100644 --- a/packages/driver/cypress/e2e/commands/querying/root.cy.js +++ b/packages/driver/cypress/e2e/commands/querying/root.cy.ts @@ -1,3 +1,4 @@ +// @ts-expect-error TODO: fix this reference const { _ } = Cypress describe('src/cy/commands/querying', () => { diff --git a/packages/driver/cypress/e2e/commands/querying/shadow_dom.cy.js b/packages/driver/cypress/e2e/commands/querying/shadow_dom.cy.ts similarity index 99% rename from packages/driver/cypress/e2e/commands/querying/shadow_dom.cy.js rename to packages/driver/cypress/e2e/commands/querying/shadow_dom.cy.ts index 63e1562b87c2..52df94ccdeb9 100644 --- a/packages/driver/cypress/e2e/commands/querying/shadow_dom.cy.js +++ b/packages/driver/cypress/e2e/commands/querying/shadow_dom.cy.ts @@ -1,3 +1,4 @@ +// @ts-expect-error TODO: fix this reference const { _ } = Cypress describe('src/cy/commands/querying - shadow dom', () => { diff --git a/packages/driver/cypress/e2e/commands/querying/within.cy.js b/packages/driver/cypress/e2e/commands/querying/within.cy.ts similarity index 96% rename from packages/driver/cypress/e2e/commands/querying/within.cy.js rename to packages/driver/cypress/e2e/commands/querying/within.cy.ts index 7b9b9b8953eb..26231c7b0e0b 100644 --- a/packages/driver/cypress/e2e/commands/querying/within.cy.js +++ b/packages/driver/cypress/e2e/commands/querying/within.cy.ts @@ -1,4 +1,4 @@ -const { assertLogLength } = require('../../../support/utils') +import { assertLogLength } from '../../../support/utils' const { _ } = Cypress @@ -30,12 +30,16 @@ describe('src/cy/commands/querying/within', () => { const span = cy.$$('#nested-div span:contains(foo)') cy.contains('foo').then(($span) => { - expect($span.get(0)).not.to.eq(span.get(0)) + const firstSpan = $span?.[0] as unknown as HTMLElement + + expect(firstSpan).not.to.eq(span.get(0)) }) cy.get('#nested-div').within(() => { cy.contains('foo').then(($span) => { - expect($span.get(0)).to.eq(span.get(0)) + const firstSpan = $span?.[0] as unknown as HTMLElement + + expect(firstSpan).to.eq(span.get(0)) }) }) }) @@ -129,6 +133,7 @@ describe('src/cy/commands/querying/within', () => { }) cy.then(() => { + // @ts-expect-error - TODO: Look at where cy._events would be defined expect(cy._events).not.to.have.property('command:start') }) }) @@ -309,6 +314,7 @@ describe('src/cy/commands/querying/within', () => { done() }) + // @ts-expect-error - testing invalid input cy.get('body').within(value) }) }) diff --git a/packages/driver/src/cy/commands/querying/querying.ts b/packages/driver/src/cy/commands/querying/querying.ts index 5416f1084054..c43f60a12afd 100644 --- a/packages/driver/src/cy/commands/querying/querying.ts +++ b/packages/driver/src/cy/commands/querying/querying.ts @@ -14,7 +14,6 @@ type GetOptions = Partial type ContainsOptions = Partial -type ShadowOptions = Partial type QueryCommandOptions = 'get' | 'contains' | 'shadow' | '' @@ -143,7 +142,7 @@ function getAlias (selector, log, cy) { } } -function validateTimeoutFromOpts (options: GetOptions | ContainsOptions | ShadowOptions = {}, queryCommand: QueryCommandOptions = '') { +function validateTimeoutFromOpts (options: GetOptions | ContainsOptions | Cypress.LogTimeoutOptions = {}, queryCommand: QueryCommandOptions = '') { if (!isEmpty(queryCommand) && _.isPlainObject(options) && options.hasOwnProperty('timeout') && !_.isFinite(options.timeout)) { $errUtils.throwErrByPath(`${queryCommand}.invalid_option_timeout`, { args: { timeout: options.timeout }, @@ -368,7 +367,8 @@ export default (Commands, Cypress, cy, state) => { } }) - Commands.addQuery('shadow', function contains (userOptions: ShadowOptions = {}) { + Commands.addQuery('shadow', function contains (userOptions: Cypress.LogTimeoutOptions) { + userOptions = userOptions || {} const log = Cypress.log({ hidden: userOptions.log === false, timeout: userOptions.timeout, diff --git a/packages/driver/src/cy/commands/querying/root.ts b/packages/driver/src/cy/commands/querying/root.ts index 939c23750e09..9d053086d7b6 100644 --- a/packages/driver/src/cy/commands/querying/root.ts +++ b/packages/driver/src/cy/commands/querying/root.ts @@ -1,5 +1,6 @@ export default (Commands, Cypress, cy, state) => { - Commands.addQuery('root', function root (options: Partial = {}) { + Commands.addQuery('root', function root (options: Cypress.LogTimeoutOptions) { + options = options || {} const log = Cypress.log({ timeout: options.timeout, hidden: options.log === false, diff --git a/packages/driver/types/internal-types-lite.d.ts b/packages/driver/types/internal-types-lite.d.ts index 91a7f26b7656..cca93dcc1195 100644 --- a/packages/driver/types/internal-types-lite.d.ts +++ b/packages/driver/types/internal-types-lite.d.ts @@ -48,7 +48,7 @@ declare namespace Cypress { * If `as` is chained to the current command, return the alias name used. */ getNextAlias: IAliases['getNextAlias'] - noop: (v: T) => Cypress.Chainable + noop: (v?: T) => Cypress.Chainable now: (string, v: T) => Cypress.Chainable queue: CommandQueue retry: IRetries['retry']