How to deal with localStorage in React testing using jest.
I have been added to setupTest.js
const localStorageMock = {
getItem: jest.fn()
setItem: jest.fn(),
removeItem: jest.fn(),
clear: jest.fn(),
};
global.localStorage = localStorageMock;
Here's example of my service to get cache:
export default class Cache {
getCache = () => {
…
Top comments (0)