added intercept for error 500

master
helenanull 4 years ago
parent 95be0423df
commit 00912cbec5

@ -0,0 +1,7 @@
{
"errors": {
"Error 500 -": [
"Internal server error"
]
}
}

@ -1,6 +1,9 @@
import login from '../selectors/login.sel'
import header from '../selectors/header.sel'
describe('Login', () => {
// context is the same as describe
context('unsuccessful', () => {
beforeEach(() => {
// visit ('/login') -> will visit baseUrl + /login
// baseUrl is set in config - cypress.json file
@ -15,10 +18,39 @@ describe('Login', () => {
.and('contain', 'email or password is invalid')
})
it('can press enter to log in', () => {
it('can see error message when username and password fields are empty', () => {
cy.get(login.signInButton).click()
cy.get(login.errorMessages).should('be.visible')
.and('contain', 'email or password is invalid')
})
it('can see error message when API responds with 500', () => {
cy.intercept('POST', 'https://conduit.productionready.io/api/users/login', {
method: 'POST',
statusCode: 500,
fixture: 'login_error'
})
cy.get(login.emailField).type('random2@test.com')
cy.get(login.passwordField).type('random_pass{enter}')
cy.get(login.errorMessages).should('be.visible')
.and('contain', 'email or password is invalid')
.and('contain', 'Error 500 - Internal server error')
})
})
context('successful', () => {
beforeEach(() => {
// we need a new user
cy.register().then((email) => {
cy.wrap(email).as('email')
})
cy.visit('/login')
})
it('can log in', function () {
cy.get(login.emailField).type(this.email)
cy.get(login.passwordField).type('Testtest1')
cy.get(login.signInButton).click()
cy.get(header.settingsLink).should('be.visible')
})
})
})

Loading…
Cancel
Save