-
-
Save lakshmankashyap/8d1bf18ae145e4a1d673e992a8e5cf3c to your computer and use it in GitHub Desktop.
Jest mock localStorage #test #jest
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ./__mocks__/localStorage.js | |
let mockStorage = {}; | |
module.exports = window.localStorage = { | |
setItem: (key, val) => Object.assign(mockStorage, {[key]: val}), | |
getItem: (key) => mockStorage[key], | |
clear: () => mockStorage = {} | |
}; | |
// Then import it in the reducer test file | |
import '../__mocks__/localStorage'; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment