From 9968d86d12185257cd1f8e2186c30477efc47336 Mon Sep 17 00:00:00 2001 From: Avichay Eyal Date: Tue, 13 Oct 2020 17:17:34 +0300 Subject: [PATCH] API Compatibility for setItem --- src/mock-localstorage.js | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/mock-localstorage.js b/src/mock-localstorage.js index 9ca75f1..91350cc 100644 --- a/src/mock-localstorage.js +++ b/src/mock-localstorage.js @@ -2,13 +2,17 @@ (function () { function createStorage() { + let UNSET = Symbol(); let s = {}, noopCallback = () => {}, _itemInsertionCallback = noopCallback; Object.defineProperty(s, 'setItem', { get: () => { - return (k, v) => { + return (k, v = UNSET) => { + if (v === UNSET) { + throw new TypeError(`Failed to execute 'setItem' on 'Storage': 2 arguments required, but only 1 present.`); + } k = k + ''; if (!s.hasOwnProperty(k)) { _itemInsertionCallback(s.length);