Skip to content

Commit

Permalink
misc: Add some missing types + Convert js driver/query tests to ts (#…
Browse files Browse the repository at this point in the history
…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
  • Loading branch information
jennifer-shehane authored Feb 24, 2025
1 parent 5da0995 commit 1e7b596
Show file tree
Hide file tree
Showing 11 changed files with 127 additions and 106 deletions.
1 change: 1 addition & 0 deletions cli/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:**

Expand Down
15 changes: 14 additions & 1 deletion cli/types/cypress.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1898,7 +1898,7 @@ declare namespace Cypress {
*
* @see https://on.cypress.io/root
*/
root<E extends Node = HTMLHtmlElement>(options?: Partial<Loggable>): Chainable<JQuery<E>> // can't do better typing unless we ignore the `.within()` case
root<E extends Node = HTMLHtmlElement>(options?: Partial<LogTimeoutOptions>): Chainable<JQuery<E>> // can't do better typing unless we ignore the `.within()` case

/**
* Take a screenshot of the application under test and the Cypress Command Log.
Expand Down Expand Up @@ -1980,6 +1980,18 @@ declare namespace Cypress {
*/
shadow(): Chainable<Subject>

/**
* 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<LogTimeoutOptions>): Chainable<Subject>

/**
* Create an assertion. Assertions are automatically retried until they pass or time out.
*
Expand Down Expand Up @@ -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().
*/
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
const { sinon } = Cypress

describe('component testing', () => {
/** @type {Cypress.Agent<sinon.SinonSpy>} */
let uncaughtExceptionStub

before(() => {
Expand All @@ -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', () => {
Expand All @@ -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' }))
Expand All @@ -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' }))
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const { assertLogLength } = require('../../../support/utils')
import { assertLogLength } from '../../../support/utils'

const { _ } = Cypress

Expand Down
Loading

4 comments on commit 1e7b596

@cypress-bot
Copy link
Contributor

@cypress-bot cypress-bot bot commented on 1e7b596 Feb 24, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Circle has built the linux arm64 version of the Test Runner.

Learn more about this pre-release build at https://on.cypress.io/advanced-installation#Install-pre-release-version

Run this command to install the pre-release locally:

npm install https://cdn.cypress.io/beta/npm/14.1.0/linux-arm64/develop-1e7b5966989a94429a4c802b4e4210596399e2d2/cypress.tgz

@cypress-bot
Copy link
Contributor

@cypress-bot cypress-bot bot commented on 1e7b596 Feb 24, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Circle has built the linux x64 version of the Test Runner.

Learn more about this pre-release build at https://on.cypress.io/advanced-installation#Install-pre-release-version

Run this command to install the pre-release locally:

npm install https://cdn.cypress.io/beta/npm/14.1.0/linux-x64/develop-1e7b5966989a94429a4c802b4e4210596399e2d2/cypress.tgz

@cypress-bot
Copy link
Contributor

@cypress-bot cypress-bot bot commented on 1e7b596 Feb 24, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Circle has built the darwin arm64 version of the Test Runner.

Learn more about this pre-release build at https://on.cypress.io/advanced-installation#Install-pre-release-version

Run this command to install the pre-release locally:

npm install https://cdn.cypress.io/beta/npm/14.1.0/darwin-arm64/develop-1e7b5966989a94429a4c802b4e4210596399e2d2/cypress.tgz

@cypress-bot
Copy link
Contributor

@cypress-bot cypress-bot bot commented on 1e7b596 Feb 24, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Circle has built the darwin x64 version of the Test Runner.

Learn more about this pre-release build at https://on.cypress.io/advanced-installation#Install-pre-release-version

Run this command to install the pre-release locally:

npm install https://cdn.cypress.io/beta/npm/14.1.0/darwin-x64/develop-1e7b5966989a94429a4c802b4e4210596399e2d2/cypress.tgz

Please sign in to comment.