Skip to content

Commit

Permalink
add comments; run prettier
Browse files Browse the repository at this point in the history
  • Loading branch information
mcshiz authored and Bryan Clark committed Jan 16, 2018
1 parent ac900f4 commit 1a31125
Showing 1 changed file with 44 additions and 51 deletions.
95 changes: 44 additions & 51 deletions src/localstorage.js
Original file line number Diff line number Diff line change
@@ -1,52 +1,45 @@
export class LocalStorage {
constructor() {
Object.defineProperty(this, "getItem", {
enumerable: false,
value: jest.fn((key) => {return this[key] || null })

});
Object.defineProperty(this, "setItem", {
enumerable: false,
value: jest.fn((key, val = '') => {
this[key] = val + '';
})
});
Object.defineProperty(this, "removeItem", {
enumerable: false,
value: jest.fn((key) => {
delete this[key];
})
});
Object.defineProperty(this, "clear", {
enumerable: false,
value: jest.fn(() => {
Object.keys(this).map(key => delete this[key]);

})
});
Object.defineProperty(this, "toString", {
enumerable: false,
value: jest.fn(() => {
return "[object Storage]"

})
});
Object.defineProperty(this, "key", {
enumerable: false,
value: jest.fn((idx) => {
return Object.keys(this)[idx] || null
})
});

} // end constructor

get length() {
return Object.keys(this).length
}

get __STORE__() {
return this
}

export class LocalStorage {
constructor(jest) {
Object.defineProperty(this, 'getItem', {
enumerable: false,
value: jest.fn(key => this[key] || null),
});
Object.defineProperty(this, 'setItem', {
enumerable: false,
// not mentioned in the spec, but we must always coerce to a string
value: jest.fn((key, val = '') => {
this[key] = val + '';
}),
});
Object.defineProperty(this, 'removeItem', {
enumerable: false,
value: jest.fn(key => {
delete this[key];
}),
});
Object.defineProperty(this, 'clear', {
enumerable: false,
value: jest.fn(() => {
Object.keys(this).map(key => delete this[key]);
}),
});
Object.defineProperty(this, 'toString', {
enumerable: false,
value: jest.fn(() => {
return '[object Storage]';
}),
});
Object.defineProperty(this, 'key', {
enumerable: false,
value: jest.fn(idx => Object.keys(this)[idx] || null),
});
} // end constructor

get length() {
return Object.keys(this).length;
}
// for backwards compatibility
get __STORE__() {
return this;
}
}

0 comments on commit 1a31125

Please sign in to comment.