Mock local storage when running tests

This commit is contained in:
Łukasz Mierzwa
2017-08-05 19:32:29 -07:00
parent ea62db3c2f
commit 4bb14312ff
2 changed files with 23 additions and 0 deletions

View File

@@ -0,0 +1,22 @@
// source: https://github.com/facebook/jest/issues/2098
var localStorageMock = (function() {
var store = {};
return {
getItem: function(key) {
return store[key] || null;
},
setItem: function(key, value) {
store[key] = value.toString();
},
clear: function() {
store = {};
}
};
})();
Object.defineProperty(window, "localStorage", {
value: localStorageMock
});

View File

@@ -1,6 +1,7 @@
const $ = require("jquery");
const templatesMock = require("./__mocks__/templatesMock");
const alertsMock = require("./__mocks__/alertsMock");
require("./__mocks__/localStorageMock");
jest.useFakeTimers();