UNPKG

jest-localstorage-mock

Version:

Auto mock all localstorage and sessionstorage APIs for your Jest tests

20 lines (17 loc) 501 B
import { LocalStorage } from './localstorage'; if (typeof global._localStorage !== 'undefined') { Object.defineProperty(global, '_localStorage', { value: new LocalStorage(jest), writable: false, }); } else { global.localStorage = new LocalStorage(jest); } if (typeof global._sessionStorage !== 'undefined') { Object.defineProperty(global, '_sessionStorage', { value: new LocalStorage(jest), writable: false, }); } else { global.sessionStorage = new LocalStorage(jest); }