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

Property 'request' does not exist on type 'HTMLElement'. during request aliasing #24823

Open
CSchulz opened this issue Nov 25, 2022 · 5 comments
Labels
stage: ready for work The issue is reproducible and in scope type: typings Issue related to Cypress types (for TypeScript)

Comments

@CSchulz
Copy link

CSchulz commented Nov 25, 2022

Current behavior

cy.get with an alias for requests returns a JQuery instead of a http response interface.

There was also no notice in the change log about a behavior change.

Desired behavior

cy.get should return Cypress.Response type to enable response status checks and similar like in the code example.

Test code to reproduce

cy.request('https://jsonplaceholder.cypress.io/comments').as('comments')

cy.get('@comments').should((response) => {
  if (response.status === 200) {
    expect(response).to.have.property('duration')
  } else {
    // whatever you want to check here
  }
})

https://docs.cypress.io/guides/core-concepts/variables-and-aliases#Requests

Cypress Version

11.2.0

Node version

16.15.0

Operating System

Windows 10

Debug Logs

No response

Other

No response

@CSchulz
Copy link
Author

CSchulz commented Nov 28, 2022

After some research by my collegue it should be Cypress.WaitXHR instead of HTMLElement.

@emilyrohrbough
Copy link
Member

emilyrohrbough commented Dec 20, 2022

@CSchulz thank you for reporting this Typescript issue. It looks like we have programmed our types for get(alias) to return a JQuery element here. TypeScript is not my strongest, but it looks like we should be stricter on our alias matches and then support just about anything since any yielded value could be aliases - jquery element, response, string, object.

Is this something you would be interested in contributing?

For the time being, you could override this type locally to get around this error.

// load the global Cypress types
/// <reference types="cypress" />

declare namespace Cypress {
  type AliasSelector = `@${string}`
  interface Chainable {
    /**
     * Custom command to select DOM element by data-cy attribute.
     * @example cy.dataCy('greeting')
     */
    get(alias: AliasSelector): Chainable<any>
  }
}

it('issue 24823', () => {
  cy.request('https://jsonplaceholder.cypress.io/comments').as('comments')

  cy.get('@comments')
  .should((response: Cypress.Response<any>) => {
    if (response.status === 200) {
      expect(response).to.have.property('duration')
    } else {
      // whatever you want to check here
    }
  })
})

@emilyrohrbough emilyrohrbough removed their assignment Jan 30, 2023
@nagash77 nagash77 added E2E Issue related to end-to-end testing Triaged Issue has been routed to backlog. This is not a commitment to have it prioritized by the team. and removed routed-to-e2e labels Apr 19, 2023
@jennifer-shehane jennifer-shehane added type: typings Issue related to Cypress types (for TypeScript) good first issue Good for newcomers and removed type: bug topic: typescript help wanted labels Oct 4, 2023
@fubha
Copy link

fubha commented Jan 10, 2024

Hi @emilyrohrbough, I am experiencing the same issue.
The workaround you mentioned above does't seem to be working at my end. Is there any update on this?
Thanks!

@jennifer-shehane jennifer-shehane added stage: ready for work The issue is reproducible and in scope and removed stage: awaiting response Potential fix was proposed; awaiting response E2E Issue related to end-to-end testing Triaged Issue has been routed to backlog. This is not a commitment to have it prioritized by the team. labels Jan 24, 2024
@jennifer-shehane jennifer-shehane removed the good first issue Good for newcomers label Jul 21, 2024
@cypress-app-bot
Copy link
Collaborator

This issue has not had any activity in 180 days. Cypress evolves quickly and the reported behavior should be tested on the latest version of Cypress to verify the behavior is still occurring. It will be closed in 14 days if no updates are provided.

@cypress-app-bot cypress-app-bot added the stale no activity on this issue for a long period label Jan 18, 2025
@matthieu-deroo
Copy link

This issue still exists in Cypress 14

@cypress-app-bot cypress-app-bot removed the stale no activity on this issue for a long period label Jan 29, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
stage: ready for work The issue is reproducible and in scope type: typings Issue related to Cypress types (for TypeScript)
Projects
None yet
Development

No branches or pull requests

9 participants