Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Assertion failing when trying to assert an ID number in a URL Path

I am trying to do the following:
Assert the URL path after being redirected.

Here is an example of the Url: https://www.hello.com/test/test-result?testId=100

cy.location("pathname").should("eq", "/test/test-result"
cy.location("search").should("eq","/\?testId=\/\d+/)

The first assertion passes, but the second one fails.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

The error I get is the following: expected ?testId=100 to equal /?testId=/\d+/

Can someone tell me what I am doing wrong? I thought using d+ would be good since it will match any number.

>Solution :

I think you should change the pattern matching ?testId=100 as follows:

cy.location("search").should("match", /\?testId=\d+/)

cy.location("search") should return the string: ?testId=100,
which can be match against regex /\?testId=\d+/.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading