Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

170
Vistas
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 la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda