Skip to content

Commit

Permalink
Merge pull request #25 from eavichay/patch-1
Browse files Browse the repository at this point in the history
API Compatibility for setItem
  • Loading branch information
Nikolay Turpitko authored Jan 15, 2021
2 parents e9d2ace + 9968d86 commit 56679f4
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/mock-localstorage.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 56679f4

Please sign in to comment.