Skip to content

Commit

Permalink
Publicly export withinSubject option on get command (#2791)
Browse files Browse the repository at this point in the history
* Publicly export withinSubject field on get requests

* Fix linting

* review adjustments
  • Loading branch information
Paul Sachs authored and flotwig committed Jul 9, 2019
1 parent 13b5a0a commit 27ccf75
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 3 deletions.
20 changes: 17 additions & 3 deletions cli/types/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -750,7 +750,7 @@ declare namespace Cypress {
* cy.get('input').should('be.disabled')
* cy.get('button').should('be.visible')
*/
get<K extends keyof HTMLElementTagNameMap>(selector: K, options?: Partial<Loggable & Timeoutable>): Chainable<JQuery<HTMLElementTagNameMap[K]>>
get<K extends keyof HTMLElementTagNameMap>(selector: K, options?: Partial<Loggable & Timeoutable & Withinable>): Chainable<JQuery<HTMLElementTagNameMap[K]>>
/**
* Get one or more DOM elements by selector.
* The querying behavior of this command matches exactly how $(…) works in jQuery.
Expand All @@ -760,7 +760,7 @@ declare namespace Cypress {
* cy.get('ul li:first').should('have.class', 'active')
* cy.get('.dropdown-menu').click()
*/
get<E extends Node = HTMLElement>(selector: string, options?: Partial<Loggable & Timeoutable>): Chainable<JQuery<E>>
get<E extends Node = HTMLElement>(selector: string, options?: Partial<Loggable & Timeoutable & Withinable>): Chainable<JQuery<E>>
/**
* Get one or more DOM elements by alias.
* @see https://on.cypress.io/get#Alias
Expand All @@ -771,7 +771,7 @@ declare namespace Cypress {
* //later retrieve the todos
* cy.get('@todos')
*/
get<S = any>(alias: string, options?: Partial<Loggable & Timeoutable>): Chainable<S>
get<S = any>(alias: string, options?: Partial<Loggable & Timeoutable & Withinable>): Chainable<S>

/**
* Get a browser cookie by its name.
Expand Down Expand Up @@ -1855,6 +1855,20 @@ declare namespace Cypress {
retryOnNetworkFailure: boolean
}

/**
* Options that control how a command behaves in the `within` scope.
* These options will determine how nodes are selected.
*/

interface Withinable {
/**
* Element to search for children in. If null, search begins from root-level DOM element.
*
* @default depends on context, null if outside of within wrapper
*/
withinSubject: JQuery | HTMLElement | null
}

/**
* Options that control how a command is logged in the Reporter
*/
Expand Down
6 changes: 6 additions & 0 deletions cli/types/tests/cypress-tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,12 @@ cy.get('body').within({ log: false }, body => {
body // $ExpectType JQuery<HTMLBodyElement>
})

cy.get('body').within(() => {
cy.get('body', { withinSubject: null }).then(body => {
body // $ExpectType JQuery<HTMLBodyElement>
})
})

cy
.get('body')
.then(() => {
Expand Down

4 comments on commit 27ccf75

@cypress-bot
Copy link
Contributor

@cypress-bot cypress-bot bot commented on 27ccf75 Jul 9, 2019

Choose a reason for hiding this comment

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

Circle CI has built linux x64 version of the Test Runner. The build is here
You can install this pre-release platform-specific build using instructions at https://on.cypress.io/installing-cypress#Install-pre-release-version.

You will need to use custom CYPRESS_INSTALL_BINARY url and install Cypress using an url instead of the version.

export CYPRESS_INSTALL_BINARY=https://cdn.cypress.io/beta/binary/3.4.0/linux-x64/circle-develop-27ccf751ba019128dc7529c424dab5e644429ea3-131615/cypress.zip
npm install https://cdn.cypress.io/beta/npm/3.4.0/circle-develop-27ccf751ba019128dc7529c424dab5e644429ea3-131605/cypress.tgz

@cypress-bot
Copy link
Contributor

@cypress-bot cypress-bot bot commented on 27ccf75 Jul 9, 2019

Choose a reason for hiding this comment

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

AppVeyor CI has built win32 x64 version of the Test Runner.
You can install this pre-release platform-specific build using instructions at https://on.cypress.io/installing-cypress#Install-pre-release-version.

You will need to use custom CYPRESS_INSTALL_BINARY url and install Cypress using an url instead of the version.

set CYPRESS_INSTALL_BINARY=https://cdn.cypress.io/beta/binary/3.4.0/win32-x64/appveyor-develop-27ccf751ba019128dc7529c424dab5e644429ea3-25851482/cypress.zip
npm install https://cdn.cypress.io/beta/binary/3.4.0/win32-x64/appveyor-develop-27ccf751ba019128dc7529c424dab5e644429ea3-25851482/cypress.zip

@cypress-bot
Copy link
Contributor

@cypress-bot cypress-bot bot commented on 27ccf75 Jul 9, 2019

Choose a reason for hiding this comment

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

AppVeyor CI has built win32 ia32 version of the Test Runner.
You can install this pre-release platform-specific build using instructions at https://on.cypress.io/installing-cypress#Install-pre-release-version.

You will need to use custom CYPRESS_INSTALL_BINARY url and install Cypress using an url instead of the version.

set CYPRESS_INSTALL_BINARY=https://cdn.cypress.io/beta/binary/3.4.0/win32-ia32/appveyor-develop-27ccf751ba019128dc7529c424dab5e644429ea3-25851482/cypress.zip
npm install https://cdn.cypress.io/beta/binary/3.4.0/win32-ia32/appveyor-develop-27ccf751ba019128dc7529c424dab5e644429ea3-25851482/cypress.zip

@cypress-bot
Copy link
Contributor

@cypress-bot cypress-bot bot commented on 27ccf75 Jul 9, 2019

Choose a reason for hiding this comment

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

Circle CI has built darwin x64 version of the Test Runner. The build is here
You can install this pre-release platform-specific build using instructions at https://on.cypress.io/installing-cypress#Install-pre-release-version.

You will need to use custom CYPRESS_INSTALL_BINARY url and install Cypress using an url instead of the version.

export CYPRESS_INSTALL_BINARY=https://cdn.cypress.io/beta/binary/3.4.0/darwin-x64/circle-develop-27ccf751ba019128dc7529c424dab5e644429ea3-131643/cypress.zip
npm install https://cdn.cypress.io/beta/npm/3.4.0/circle-develop-27ccf751ba019128dc7529c424dab5e644429ea3-131641/cypress.tgz

Please sign in to comment.