Skip to content

Instantly share code, notes, and snippets.

@slawekradzyminski
Created July 3, 2021 04:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save slawekradzyminski/80e728fc0de42b919705c0ea4ace33d4 to your computer and use it in GitHub Desktop.
Save slawekradzyminski/80e728fc0de42b919705c0ea4ace33d4 to your computer and use it in GitHub Desktop.
/// <reference types="cypress" />
describe('login page', () => {
const firstName = 'Slawek'
beforeEach(() => {
cy.visit('/login')
})
it('should login', () => {
cy.intercept('POST', 'http://localhost:4000/users/authenticate', {
statusCode: 200,
body: {
firstName: firstName,
lastName: 'Radzyminski',
id: 1,
token: '123456',
username: 'slawek'
},
})
cy.get('[name=username]').type('username')
cy.get('[name=password]').type('password')
cy.get('.btn-primary').click()
cy.get('p').should('contain.text', 'Congratulations')
cy.get('h1').should('contain.text', firstName)
})
it('should show error message after unsuccessful login', () => {
cy.get('[name=username]').type('wrong')
cy.get('[name=password]').type('wrong')
cy.get('.btn-primary').click()
cy.get('.alert-danger').should('contain.text', 'Login failed')
})
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment