-
Notifications
You must be signed in to change notification settings - Fork 33
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
getItem and setItem value implementation for localstorage #110
Comments
I'm having a similar issue. after doing this causes problems because my code is the way I solved my problem was: (also I remove this plugin and was still getting the same functionality/problem.... I wonder what was up with that.......... 🤔) |
Actually if you do "localStorage.setItem('token', null)" and "localStorage.getItem('token')" following that it should give you "null". That is actually the correct behavior according to the W3C specifications for localStorage. The image below shows the behavior in Safari, Firefox and Chrome. So you might want to check your code's behavior in the browsers. The mock does not follow the behavior of the specifications. Since it stores and returns the values as the type that you supplies to it |
True....! and now I can't replicate my problem on my tests..... not sure why..... 🤔 |
Hi,
Thanks for the nice work in creating this. I was working with it and I am wondering it both the setItem and getItem should force the value to become a string. Looking back into the specs. The interface shows that the values should be DOMString. I am not sure if I am reading the DOMString spec right but that appears to be a string as well. Mozilla indicates it to be a string as well.
I am wondering if there might be code required to handle JSON values as well. I tried accessing the store for github and I think the value is converted to be a string on Chrome and Firefox when the value is a json object
jest-localstorage-mock/src/localstorage.js
Lines 3 to 13 in 50f3dfb
Image of localStorage.getItem in Chrome and Mozilla for json values
Image of interface for localStorage
Reference: https://html.spec.whatwg.org/multipage/webstorage.html
DOMString:
https://heycam.github.io/webidl/#idl-DOMString
https://developer.mozilla.org/en-US/docs/Web/API/DOMString
The text was updated successfully, but these errors were encountered: