fix: cy.then shows wrong type when raw HTMLElement is provided. (#15624)

Co-authored-by: Chris Breiding <chrisbreiding@users.noreply.github.com>
This commit is contained in:
Kukhyeon Heo
2021-03-30 00:23:09 +09:00
committed by GitHub
parent d8fb895765
commit 03c8da01fa
2 changed files with 32 additions and 0 deletions
+12
View File
@@ -1824,6 +1824,12 @@ declare namespace Cypress {
* @see https://on.cypress.io/then
*/
then<S>(options: Partial<Timeoutable>, fn: (this: ObjectLike, currentSubject: Subject) => PromiseLike<S>): Chainable<S>
/**
* Enables you to work with the subject yielded from the previous command / promise.
*
* @see https://on.cypress.io/then
*/
then<S extends HTMLElement>(fn: (this: ObjectLike, currentSubject: Subject) => S): Chainable<JQuery<S>>
/**
* Enables you to work with the subject yielded from the previous command / promise.
*
@@ -1836,6 +1842,12 @@ declare namespace Cypress {
* @see https://on.cypress.io/then
*/
then<S>(fn: (this: ObjectLike, currentSubject: Subject) => S): ThenReturn<Subject, S>
/**
* Enables you to work with the subject yielded from the previous command / promise.
*
* @see https://on.cypress.io/then
*/
then<S extends HTMLElement>(options: Partial<Timeoutable>, fn: (this: ObjectLike, currentSubject: Subject) => S): Chainable<JQuery<S>>
/**
* Enables you to work with the subject yielded from the previous command / promise.
*
+20
View File
@@ -236,6 +236,26 @@ describe('then', () => {
s // $ExpectType string
})
})
it('HTMLElement', () => {
cy.get('div')
.then(($div) => {
$div // $ExpectType JQuery<HTMLDivElement>
return $div[0]
})
.then(($div) => {
$div // $ExpectType JQuery<HTMLDivElement>
})
cy.get('p')
.then(($p) => {
$p // $ExpectType JQuery<HTMLParagraphElement>
return $p[0]
})
.then({timeout: 3000}, ($p) => {
$p // $ExpectType JQuery<HTMLParagraphElement>
})
})
})
cy.wait(['@foo', '@bar'])