Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

166
Views
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
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!