Reputation: 2528
I do have backend ready. But i wish that my front end while testing use mock server only which we can create in cypress. My test is
cy.server()
cy.route({
method:'POST',
url:'/dashboard/v1/public/login',
status:404,
response:{
"error": true,
"message": "User with above credentials does not exists"
}
})
cy.get('[data-testid="loging-page-email-input')
.type('[email protected]')
cy.get('[data-testid="loging-page-password-input')
.type('test123')
cy.get('[data-testid="loging-page-button-clicked')
.type('{enter}')
cy.get('[data-testid="loging-page-auth-error-msg') // Here it should grab alert box
But the problem is that same credentials are correct if we want to login to website physically. So if cypress is able to login it then we can see that it is not taking data that we are providing in
cy.route({
method:'POST',
url:'/dashboard/v1/public/login',
status:404,
response:{
"error": true,
"message": "User with above credentials does not exists"
}
})
Instead it is making api call and is able to login.
Any idea whats going wrong ? More over my base url is http://localhost:3000
but my full login api url is y.x.in/dashboard/v1/public/login
cy.server()
cy.route({
method:'POST',
url:'/dashboard/v1/public/login',
body:{
email:"[email protected]",
password:"sss"
},
status:404,
response:{
"error": true,
"message": "User with above credentials does not exists"
}
})
Upvotes: 0
Views: 806
Reputation: 365
Try this approach, please notice that method
, url
and response
are out of the options
param.
cy.server()
cy.route({
method:'POST',
url:'/dashboard/v1/public/login',
response: {
"error": true,
"message": "User with above credentials does not exists"
},
status:404,
options: {
body:{
email:"[email protected]",
password:"sss"
}
}
})
Upvotes: 1