clarkbw / jest-localstorage-mock

A module to mock window.localStorage and window.sessionStorage in Jest

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

getItem() bug

Katarn opened this issue · comments

I seem to have found the wrong work of getItem() method. Try this code in browser console and mock:

localStorage.setItem("param", 1);

typeof JSON.parse(localStorage.getItem("param")); // "number" in Chrome and "string" in this mock

It not bug in JSON.parse() method because I also tested typeof JSON.parse("1") in Node and it was "number".

This likely comes from out setItem method that appends a string. https://github.com/clarkbw/jest-localstorage-mock/blob/master/src/localstorage.js