Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'spec/frontend/helpers/local_storage_helper.js')
-rw-r--r--spec/frontend/helpers/local_storage_helper.js20
1 files changed, 14 insertions, 6 deletions
diff --git a/spec/frontend/helpers/local_storage_helper.js b/spec/frontend/helpers/local_storage_helper.js
index 48e66b11767..a66c31d1353 100644
--- a/spec/frontend/helpers/local_storage_helper.js
+++ b/spec/frontend/helpers/local_storage_helper.js
@@ -28,12 +28,20 @@ const useLocalStorage = fn => {
/**
* Create an object with the localStorage interface but `jest.fn()` implementations.
*/
-export const createLocalStorageSpy = () => ({
- clear: jest.fn(),
- getItem: jest.fn(),
- setItem: jest.fn(),
- removeItem: jest.fn(),
-});
+export const createLocalStorageSpy = () => {
+ let storage = {};
+
+ return {
+ clear: jest.fn(() => {
+ storage = {};
+ }),
+ getItem: jest.fn(key => storage[key]),
+ setItem: jest.fn((key, value) => {
+ storage[key] = value;
+ }),
+ removeItem: jest.fn(key => delete storage[key]),
+ };
+};
/**
* Before each test, overwrite `window.localStorage` with a spy implementation.