When using cy.location('pathname') , asserting throws error.
assertion looks like this:
cy.location('pathname').should("eq", `/onboarding/name`)
error:
CypressError: Location object does not have key: pathname
fyi: writing out assertion with function works no problem:
cy.location().should(function(location){
expect(location.pathname).to.eq('/events')
})
Should not throw error, when trying to use cy.location('pathname')
in this particular case, the assertion comes right after redirect after login
looks like this. you can see the test does not wait for path change and throws an error.


I'm having this issue as well.
What's most interesting is that it's not consistent, however, it ONLY occurs with the cypress run command.
Regardless of whether it is run normally or with the --headed flag, it will happen 70-80% of the time, and is causing my tests to needlessly fail...
I cannot understand why or what the difference between running this via cypress open or just cypress run is. Even though I'm using Electron 57 for cypress open...
It works with cy.window()
it('signs in to backoffice', () => {
cy.window().then((win) => {
expect(win.location.pathname).to.equal('/backoffice')
})
})
issue replicated doing like:
cy.location('pathname').should($pathname =>
Tried to reproduce the problem, but failed.
You can see the failed attempts here.
I both tested with cypress:open and cypress:run. Both are fine.
If anyone encounters with this problem, please leave an example code/project that fails.
Thanks.
p.s.
My environment:
Cypress version has gone up a lot. It is possible that it's been fixed.
Closing as resolved. Please comment with a completely reproducible example if you are still having this issue and we will consider reopening.
Most helpful comment
It works with cy.window()