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

cy.get('@aliasOfIntercept) return null #9306

Closed
kamiloski opened this issue Nov 24, 2020 · 5 comments · Fixed by #9594
Closed

cy.get('@aliasOfIntercept) return null #9306

kamiloski opened this issue Nov 24, 2020 · 5 comments · Fixed by #9594

Comments

@kamiloski
Copy link

kamiloski commented Nov 24, 2020

Current behavior

Till now (before v6) i could get data eg request.body using cy.get(aliasOf cy.route) if request occurs. Now I get on the same code which works before.

Timed out retrying: cy.its() errored because your subject is: null. You cannot access any properties such as request on a null value.
If you expect your subject to be null, then add an assertion such as:
cy.wrap(null).should('be.null')

Desired behavior

I should get data from request

Test code to reproduce

 cy.intercept('PATCH', ${uriPatch}`).as('update_success')
 cy.wait('@update_success').its('response.statusCode').should('eq', 200)
        if (Array.isArray(bodyJson)) {
            cy.get('@update_success').its('request.body').should('deep.equal', bodyJson)    <- here I get this null, works till v6
        } else {
            cy.get('@update_success').its('request.body').should('deep.include', bodyJson)  <- here I get this null, works till v6
        }

Versions

6.0.0

@jennifer-shehane jennifer-shehane added topic: cy.intercept() type: unexpected behavior User expected result, but got another v6.0.0 🐛 Issue present since 6.0.0 type: bug and removed type: unexpected behavior User expected result, but got another labels Nov 24, 2020
@jennifer-shehane
Copy link
Member

Yeah, this is a bug.

Reproducible example

it('test cy.intercept()', () => {
  cy.intercept('url').as('getUrl')
  cy.visit('https://example.com')
  cy.window().then((win) => {
    const xhr = new win.XMLHttpRequest()
    xhr.open('GET', '/url')
    xhr.send()
  })
  
  cy.wait('@getUrl').should((interception) => {
    expect(interception).to.not.be.null
    expect(interception).to.not.be.null
  })
  cy.get('@getUrl').should((interception) => {
    expect(interception).to.not.be.null
  })
})

Screen Shot 2020-11-25 at 4 05 17 PM

@cypress-bot cypress-bot bot added the stage: ready for work The issue is reproducible and in scope label Nov 25, 2020
@pete-om
Copy link

pete-om commented Nov 26, 2020

Hi @jennifer-shehane is it safe to assume that when this bug is fixed, the extra dot commands like cy.get('@alias.all') will also work again?

Cheers!

@FrancisBourgault
Copy link

FrancisBourgault commented Nov 30, 2020

I don't know if this is related, but I found that when using cy.wait (instead of cy.get), then the interception object is null only when the request is aborted. Otherwise, the interception object has both the request and the response.

Here how I stumble on this issue (see linked images)
cypress_request_aborted_code
cypress_request_aborted_execution

I commented the code to translate what each command of my framework does so you can reproduce it.

There doesn't seem to be a replacement for "xhr.aborted" for the cy.wait() from version <6.0.0. Will there be an implementation for that in a future release?

UPDATE: Not fixed by updating to 6.0.1

@cypress-bot cypress-bot bot added stage: needs review The PR code is done & tested, needs review and removed stage: ready for work The issue is reproducible and in scope labels Dec 9, 2020
@cypress-bot
Copy link
Contributor

cypress-bot bot commented Dec 9, 2020

The code for this is done in cypress-io/cypress#9594, but has yet to be released.
We'll update this issue and reference the changelog when it's released.

@cypress-bot cypress-bot bot added stage: pending release and removed stage: needs review The PR code is done & tested, needs review labels Dec 9, 2020
@cypress-bot
Copy link
Contributor

cypress-bot bot commented Dec 21, 2020

Released in 6.2.0.

This comment thread has been locked. If you are still experiencing this issue after upgrading to
Cypress v6.2.0, please open a new issue.

@cypress-bot cypress-bot bot locked as resolved and limited conversation to collaborators Dec 21, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants