Skip to content

Commit

Permalink
Revert "Provide strong types for 'invoke' command (#4022) (#4907)"
Browse files Browse the repository at this point in the history
This reverts commit 15685db.

The type for `invoke` command seems to break jQuery method
that take an argument like

```js
cy.get('.trigger-input-range')
  .invoke('val', 25)
```
  • Loading branch information
bahmutov committed Aug 6, 2019
1 parent 15685db commit 6930cab
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 30 deletions.
23 changes: 8 additions & 15 deletions cli/types/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
// Mike Woudenberg <https://github.com/mikewoudenberg>
// Robbert van Markus <https://github.com/rvanmarkus>
// Nicholas Boll <https://github.com/nicholasboll>
// TypeScript Version: 3.0
// TypeScript Version: 2.8
// Updated by the Cypress team: https://www.cypress.io/about/

/// <reference path="./cy-blob-util.d.ts" />
Expand Down Expand Up @@ -810,22 +810,15 @@ declare namespace Cypress {
hash(options?: Partial<Loggable & Timeoutable>): Chainable<string>

/**
* Invoke a function on the previously yielded subject, yielding the result.
* Invoke a function on the previously yielded subject.
* This isn't possible to strongly type without generic override yet.
* If called on an object you can do this instead: `.then(s => s.show())`.
* If called on an array you can do this instead: `.each(s => s.show())`.
* From there the subject will be properly typed.
*
* @see https://on.cypress.io/invoke
* @example
* // Invoke the 'add' function, passing in parameters
* cy.wrap({ add: (a, b) => a + b }).invoke('add', 1, 2).should('eq', 3)
* // DOM elements are automatically wrapped with jQuery,
* // so jQuery functions (including 3rd party plugins) can be invoked
* cy.get('.modal').invoke('show').should('be.visible') // jQuery's 'show' functions
*/
invoke<
TActualSubject extends (Subject extends Node | Node[] ? JQuery<Subject> : Subject),
TName extends ({ [K in keyof TActualSubject]: TActualSubject[K] extends (...args: any[]) => any ? K : never }[keyof TActualSubject]),
TArgs extends (TActualSubject[TName] extends (...args: infer A) => any ? A : never),
TReturn extends (TActualSubject[TName] extends (...args: any[]) => infer R ? R : never),
>(functionName: TName, ...args: TArgs): Chainable<TReturn>
*/
invoke(functionName: keyof Subject, ...args: any[]): Chainable<Subject> // don't have a way to express return types yet

/**
* Get a property’s value on the previously yielded subject.
Expand Down
15 changes: 0 additions & 15 deletions cli/types/tests/cypress-tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -317,18 +317,3 @@ namespace CypressContainsTests {
cy.contains('#app', 'my text to find', {log: false, timeout: 100})
cy.contains('my text to find', {log: false, timeout: 100})
}

namespace CypressInvokeTests {
const obj = {
foo: (value: number, name = 'n') => `${ name } = ${ value + 1 }`,
bar: { baz: (a: number) => a + 1 }
}
cy.wrap(obj).invoke('foo', 1).should('equal', 'n = 2') // $ExpectType Chainable<string>
cy.wrap(obj).invoke('foo', 5, 'b').should('equal', 'b = 6') // $ExpectType Chainable<string>
cy.wrap(obj).its('bar').invoke('baz', 2).should('equal', 3) // $ExpectType Chainable<number>
cy.wrap(obj).invoke('bar', 2) // $ExpectError
cy.wrap(obj).invoke('bar.baz', 2).should('equal', 3) // $ExpectError
cy.wrap(obj).invoke('foo', 5, 1) // $ExpectError
cy.wrap(obj).invoke('foo', 5, 'b', 1) // $ExpectError
cy.get('input').then(it => it[0]).invoke('checkValidity') // $ExpectError
}

4 comments on commit 6930cab

@cypress-bot
Copy link
Contributor

@cypress-bot cypress-bot bot commented on 6930cab Aug 6, 2019

Choose a reason for hiding this comment

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

Circle has built the linux 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.

export CYPRESS_INSTALL_BINARY=https://cdn.cypress.io/beta/binary/3.5.0/linux-x64/circle-develop-6930cabd7bbad52be44212914ffac7a738ec7a78-144715/cypress.zip
npm install https://cdn.cypress.io/beta/npm/3.5.0/circle-develop-6930cabd7bbad52be44212914ffac7a738ec7a78-144702/cypress.tgz

@cypress-bot
Copy link
Contributor

@cypress-bot cypress-bot bot commented on 6930cab Aug 6, 2019

Choose a reason for hiding this comment

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

AppVeyor has built the 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.5.0/win32-ia32/appveyor-develop-6930cabd7bbad52be44212914ffac7a738ec7a78-26513254/cypress.zip
npm install https://cdn.cypress.io/beta/binary/3.5.0/win32-ia32/appveyor-develop-6930cabd7bbad52be44212914ffac7a738ec7a78-26513254/cypress.zip

@cypress-bot
Copy link
Contributor

@cypress-bot cypress-bot bot commented on 6930cab Aug 6, 2019

Choose a reason for hiding this comment

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

AppVeyor has built the 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.5.0/win32-x64/appveyor-develop-6930cabd7bbad52be44212914ffac7a738ec7a78-26513254/cypress.zip
npm install https://cdn.cypress.io/beta/binary/3.5.0/win32-x64/appveyor-develop-6930cabd7bbad52be44212914ffac7a738ec7a78-26513254/cypress.zip

@cypress-bot
Copy link
Contributor

@cypress-bot cypress-bot bot commented on 6930cab Aug 6, 2019

Choose a reason for hiding this comment

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

Circle has built the darwin 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.

export CYPRESS_INSTALL_BINARY=https://cdn.cypress.io/beta/binary/3.5.0/darwin-x64/circle-develop-6930cabd7bbad52be44212914ffac7a738ec7a78-144742/cypress.zip
npm install https://cdn.cypress.io/beta/npm/3.5.0/circle-develop-6930cabd7bbad52be44212914ffac7a738ec7a78-144740/cypress.tgz

Please sign in to comment.