Skip to content
This repository was archived by the owner on Mar 5, 2022. It is now read-only.

Conversation

@dmtrKovalenko
Copy link
Contributor

No description provided.

cy.contains('a', 'Home').click()

cy.contains('h2', 'Home')
cy.location('pathname').should('not.equal', '/')
Copy link
Contributor

Choose a reason for hiding this comment

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

so is it changing the location or not? And does MemoryRouter have some state we could check in our test directly to confirm navigation?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

No it's not. And it's the main reason of using it, it is not changing url directly and allows to mock browser history.

We are testing that it works by asserting h2 to contain proper text. Home or About.

Copy link
Contributor

Choose a reason for hiding this comment

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

I mean the cy.location in this case is extremely confusing since it returns the spec filename :)

Screen Shot 2020-09-16 at 1 04 57 PM

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes because the original href is spec path. This confirms that url in browser not changing but tests works.

Copy link
Contributor

Choose a reason for hiding this comment

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

Right - but the assertion can pass for the wrong reason (it could not go to the about page, and yet no match /). See how I changed it to have positive assertions and added readme and screenshot gif explaining what is going on.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I would not say it is the best way to change it. Only for example, from the user perspective – in tests with memory router we care about what rendered, right? We are checking it with assertions that shows in h2.

Assertion for file name could also be a variant, but easy to break :)

Copy link
Contributor

Choose a reason for hiding this comment

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

good point, I moved the location assertion after the component text assertion. But other than that - yes, the user should in this case only assert the right component is rendered in the DOM, not the URL. I did URL mostly to confirm that the URL is NOT changing when using memory router

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Maybe also a good example would be to show how cy.visit works. I hope it would not have any effect

@bahmutov bahmutov merged commit 14eb6aa into main Sep 16, 2020
@bahmutov bahmutov deleted the chore/in-memory-react-router branch September 16, 2020 19:38
@bahmutov
Copy link
Contributor

🎉 This PR is included in version 4.14.1 🎉

The release is available on:

Your semantic-release bot 📦🚀

dmtrKovalenko added a commit to cypress-io/cypress that referenced this pull request Oct 1, 2020
…st#424)

Co-authored-by: Gleb Bahmutov <gleb.bahmutov@gmail.com>
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants