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

Examples for Typescript type parameters for cy.intercept and cy.wait #5831

Open
wants to merge 8 commits into
base: main
Choose a base branch
from

Conversation

cacieprins
Copy link
Contributor

@cacieprins cacieprins commented May 22, 2024

This covers changes introduced by: cypress-io/cypress#29508

cy.intercept('/activities/*').as('getActivities')

// As templated types:
cy.wait<CustomRequest, CustomResponse>('@getUsers').then(

Choose a reason for hiding this comment

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

The types here will need to match the ones above (and in the callback body):
cy.wait<UserReq, UserRes>(...


// As inferred types, with type `Interception` available in `cypress/types/net-stubbing`
cy.wait('@getUsers').then(
({ request, response }: Interception<CustomRequest, CustomResponse>) => {

Choose a reason for hiding this comment

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

Similarly to above, the types should match the above (and expected by the callback body):
...Interception<UserReq, UserRes>...

}
)

// When passing an array of aliases, types must me inferred:

Choose a reason for hiding this comment

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

Looks like a typo here :)
mebe

cy.wait(['@getUsers', 'getActivities']).then(
(
interceptions: Array<
Interception<UserReq | ActivityReq, UserRes, ActivityRes>

Choose a reason for hiding this comment

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

Small typo here:
Interception<UserReq | ActivityReq, UserRes | ActivityRes>
(note the comma → pipe)

@cacieprins
Copy link
Contributor Author

@scottmcginness Thank you for your feedback! I'd gone back and forth on a few different edits, and missed updating some of them. Thanks for catching them!

Base automatically changed from v13.11.0 to main June 4, 2024 20:07
@cacieprins cacieprins requested a review from mschile June 5, 2024 19:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants