Skip to content

Commit

Permalink
Publicly export withinSubject field on get requests
Browse files Browse the repository at this point in the history
  • Loading branch information
paul-sachs committed Nov 15, 2018
1 parent 7640eeb commit 3429480
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 3 deletions.
19 changes: 16 additions & 3 deletions cli/types/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -652,7 +652,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 @@ -662,7 +662,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 @@ -673,7 +673,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 @@ -1622,6 +1622,19 @@ declare namespace Cypress {
whitelist: string | string[] | RegExp | ((cookie: any) => boolean)
}

/**
* Options that control how a command behaves in the `within` scope
*/

interface Withinable {
/**
* The subject of the within wrapper.
*
* @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 @@ -183,6 +183,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

0 comments on commit 3429480

Please sign in to comment.