fix: Add timeout option to the invoke and its types (#8453)

Co-authored-by: Gleb Bahmutov <gleb.bahmutov@gmail.com>
This commit is contained in:
David Mejorado
2020-11-03 11:44:19 -08:00
committed by GitHub
parent d2b8806d7c
commit a52b7736d5
2 changed files with 10 additions and 5 deletions
+5 -5
View File
@@ -1107,7 +1107,7 @@ declare namespace Cypress {
...args: any[]
): Chainable<R>
invoke<K extends keyof Subject, F extends ((...args: any[]) => any) & Subject[K], R = ReturnType<F>>(
options: Loggable,
options: Partial<Loggable & Timeoutable>,
functionName: K,
...args: any[]
): Chainable<R>
@@ -1117,7 +1117,7 @@ declare namespace Cypress {
* @see https://on.cypress.io/invoke
*/
invoke<T extends (...args: any[]) => any, Subject extends T[]>(index: number): Chainable<ReturnType<T>>
invoke<T extends (...args: any[]) => any, Subject extends T[]>(options: Loggable, index: number): Chainable<ReturnType<T>>
invoke<T extends (...args: any[]) => any, Subject extends T[]>(options: Partial<Loggable & Timeoutable>, index: number): Chainable<ReturnType<T>>
/**
* Invoke a function on the previously yielded subject by a property path.
@@ -1138,8 +1138,8 @@ declare namespace Cypress {
* // Drill into nested properties by using dot notation
* cy.wrap({foo: {bar: {baz: 1}}}).its('foo.bar.baz')
*/
its<K extends keyof Subject>(propertyName: K, options?: Loggable): Chainable<Subject[K]>
its(propertyPath: string, options?: Loggable): Chainable
its<K extends keyof Subject>(propertyName: K, options?: Partial<Loggable & Timeoutable>): Chainable<Subject[K]>
its(propertyPath: string, options?: Partial<Loggable & Timeoutable>): Chainable
/**
* Get a value by index from an array yielded from the previous command.
@@ -1147,7 +1147,7 @@ declare namespace Cypress {
* @example
* cy.wrap(['a', 'b']).its(1).should('equal', 'b')
*/
its<T, Subject extends T[]>(index: number, options?: Loggable): Chainable<T>
its<T, Subject extends T[]>(index: number, options?: Partial<Loggable & Timeoutable>): Chainable<T>
/**
* Get the last DOM element within a set of DOM elements.
+5
View File
@@ -128,6 +128,9 @@ namespace CypressItsTests {
s
})
cy.wrap({baz: { quux: '2' }}).its('baz.quux') // $ExpectType Chainable<any>
cy.wrap({foo: 'bar'}).its('foo', { log: true }) // $ExpectType Chainable<string>
cy.wrap({foo: 'bar'}).its('foo', { timeout: 100 }) // $ExpectType Chainable<string>
cy.wrap({foo: 'bar'}).its('foo', { log: true, timeout: 100 }) // $ExpectType Chainable<string>
}
namespace CypressInvokeTests {
@@ -137,6 +140,8 @@ namespace CypressInvokeTests {
cy.wrap({ a: returnsString }).invoke('a') // $ExpectType Chainable<string>
cy.wrap({ b: returnsNumber }).invoke('b') // $ExpectType Chainable<number>
cy.wrap({ b: returnsNumber }).invoke({ log: true }, 'b') // $ExpectType Chainable<number>
cy.wrap({ b: returnsNumber }).invoke({ timeout: 100 }, 'b') // $ExpectType Chainable<number>
cy.wrap({ b: returnsNumber }).invoke({ log: true, timeout: 100 }, 'b') // $ExpectType Chainable<number>
// challenging to define a more precise return type than string | number here
cy.wrap([returnsString, returnsNumber]).invoke(1) // $ExpectType Chainable<string | number>