Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

165
Visualizações
How to check the value of localstorage after login in Cypress?

I have an Angular app with Cypress for end-to-end testing.

I am testing my login page to see if the localstorage is set correctly.

This is the cypress js file:

describe('LOGIN MODULE', () => {
  it('sets the LocalStorage correctly', () => {
    cy.visit('https://www.example.com');
    cy.get('[formcontrolname="username"]').type('user');
    cy.get('[formcontrolname="password"]').type('password', { log: false });
    cy.get('form')
      .submit()
      .then(() => {
          localStorage.getItem('user').then($user => {   <=== Error on this line
          expect($user.includes('customerNr')).to.equal(true);
        });
      });
  });
});

The user item in the localstorage is as json string and looks like this:

{
  "fullName": "my name",
  "email": "my email",
  "customerNr": "1234",
  "token": "my token",
  "userId": "my userid",
  "userName": "my username",
  "roles": [
    "role 1"
  ]
}

I want to check if the user item exists and if the nested properties (fullName, email,...) have the correct values for this user.

But I am stuck on this error: "Cannot read properties of null (reading 'then')" on localStorage.getItem('user')

about 4 years ago · Santiago Trujillo
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda