-
Notifications
You must be signed in to change notification settings - Fork 76
chore: Add in-memory router example #424
Conversation
| cy.contains('a', 'Home').click() | ||
|
|
||
| cy.contains('h2', 'Home') | ||
| cy.location('pathname').should('not.equal', '/') |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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 :)
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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
|
🎉 This PR is included in version 4.14.1 🎉 The release is available on: Your semantic-release bot 📦🚀 |
…st#424) Co-authored-by: Gleb Bahmutov <gleb.bahmutov@gmail.com>

No description provided.