Skip to content

Commit

Permalink
fix: empty string no longer coalesces into null (#121)
Browse files Browse the repository at this point in the history
* fix: empty string no longer coalesces into null

* fix: empty string no longer coalesces into null

Co-authored-by: Zachary Mayry <[email protected]>
Co-authored-by: Bryan Clark <[email protected]>
3 people authored Dec 15, 2020

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
1 parent e70a179 commit 9bcc9b3
Showing 2 changed files with 21 additions and 1 deletion.
20 changes: 20 additions & 0 deletions __tests__/localstorage.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import { LocalStorage } from "../src/localstorage";

describe("localstorage", () => {
let localStorage;

beforeEach(() => {
localStorage = new LocalStorage(jest);
});

describe("getItem", () => {
it("should return null if the item is undefined", () => {
expect(localStorage.getItem("item")).toBeNull();
});

it("should return '' instead of null", () => {
localStorage.setItem("item", "");
expect(localStorage.getItem("item")).toBe("");
});
});
});
2 changes: 1 addition & 1 deletion src/localstorage.js
Original file line number Diff line number Diff line change
@@ -2,7 +2,7 @@ export class LocalStorage {
constructor(jest) {
Object.defineProperty(this, 'getItem', {
enumerable: false,
value: jest.fn(key => this[key] || null),
value: jest.fn(key => this[key] !== undefined ? this[key] : null),
});
Object.defineProperty(this, 'setItem', {
enumerable: false,

0 comments on commit 9bcc9b3

Please sign in to comment.