question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

localStorage is not being resolved sometimes

See original GitHub issue

when i’m using localStorage.getItem in before function to get some user data from storage sometimes (randomly) it is not being resolved by test engine so it spews error Uncaught TypeError: Cannot read property 'getItem' of null

to fix this use window.localStorage.getItem

i can’t provide steps to reproduce or other useful info so i believe this bug will be closed soon but i’m posting this workaround for guys who has the same issue so they can google for answer

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:1
  • Comments:11 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
jennifer-shehanecommented, Apr 24, 2019

And where is the localStorage.getItem being called that you said is throwing the error in the context of the tests above?

0reactions
TrejGuncommented, Sep 10, 2019

@Uzlopak the problem is i’m doing this in app, not in tests. App knows nothing about cy.window() and it should not Probably I should mock my global object aka window to use cy.window(). but when i use window.localStorage it works, so i dont need to mock it

Read more comments on GitHub >

github_iconTop Results From Across the Web

localStorage is not working on google chrome
LocalStorage supports only string values, not boolean or others. Method to store and retrieve values: Put the value into storage
Read more >
[solved] localStorage.setItem not working on the js file, but ...
This might be an issue of when the data is saved. The script will save it immediately when the page loads, but if...
Read more >
React localStorage: set and get items with hooks
Learn the basics of React localStorage. In this tutorial, we'll focus on how to use the localStorage storage type with React and hooks....
Read more >
LocalStorage, sessionStorage
The localStorage is shared between all windows with the same origin, so if we set the data in one window, the change becomes...
Read more >
jQuery click function with localStorage not working (may be!)
theme-item .btn').attr('aria-pressed', 'true');. So, you're saying that if the color is supposed to be ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found