Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Publicly export withinSubject option on get command #2791

Merged
merged 7 commits into from
Jul 9, 2019
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
19 changes: 16 additions & 3 deletions cli/types/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -740,7 +740,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 @@ -750,7 +750,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 @@ -761,7 +761,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 @@ -1803,6 +1803,19 @@ declare namespace Cypress {
whitelist: string | string[] | RegExp | ((cookie: any) => boolean)
}

/**
* Options that control how a command behaves in the `within` scope
jennifer-shehane marked this conversation as resolved.
Show resolved Hide resolved
*/

interface Withinable {
/**
* The subject of the within wrapper.
jennifer-shehane marked this conversation as resolved.
Show resolved Hide resolved
*
* @default depends on context, null if outside of within wrapper
*/
withinSubject: JQuery | null
flotwig marked this conversation as resolved.
Show resolved Hide resolved
}

/**
* 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 @@ -208,6 +208,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