Skip to content

Commit d0301a0

Browse files
committed
add localStora mock
1 parent 247110e commit d0301a0

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

config/polyfills.js

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,3 +28,25 @@ Object.assign = require('object-assign');
2828
if (process.env.NODE_ENV === 'test') {
2929
require('raf').polyfill(global);
3030
}
31+
32+
// localStorage
33+
const localStorageMock = (function() {
34+
let store = {};
35+
36+
return {
37+
getItem: function(key) {
38+
return store[key] || null;
39+
},
40+
setItem: function(key, value) {
41+
store[key] = value.toString();
42+
},
43+
clear: function() {
44+
store = {};
45+
}
46+
};
47+
48+
})();
49+
50+
Object.defineProperty(window, 'localStorage', {
51+
value: localStorageMock
52+
});

0 commit comments

Comments
 (0)