Skip to content

Commit

Permalink
Add note to README, run prettier (#123)
Browse files Browse the repository at this point in the history
* Add note to README, run prettier

* Don't need circleci anymore
  • Loading branch information
Bryan Clark authored Dec 16, 2020
1 parent 9bcc9b3 commit 5ad2dde
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 57 deletions.
43 changes: 0 additions & 43 deletions .circleci/config.yml

This file was deleted.

4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ module dependencies by using this.
[![Greenkeeper badge](https://badges.greenkeeper.io/clarkbw/jest-localstorage-mock.svg)](https://greenkeeper.io/)
[![Twitter](https://img.shields.io/twitter/url/https/github.com/clarkbw/jest-localstorage-mock.svg?style=social)](https://twitter.com/intent/tweet?text=Wow:&url=%5Bobject%20Object%5D)

# Jest 24+

Note that with `jest@24` and above this project potentially duplicating functionality.

## Install

This should only be installed as a development dependency (`devDependencies`) as
Expand Down
2 changes: 1 addition & 1 deletion __tests__/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
describe('storage', () =>
[localStorage, sessionStorage].map(storage => {
[localStorage, sessionStorage].map((storage) => {
// https://html.spec.whatwg.org/multipage/webstorage.html#storage
beforeEach(() => {
storage.clear();
Expand Down
14 changes: 7 additions & 7 deletions __tests__/localstorage.test.js
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
import { LocalStorage } from "../src/localstorage";
import { LocalStorage } from '../src/localstorage';

describe("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();
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("");
localStorage.setItem('item', '');
expect(localStorage.getItem('item')).toBe('');
});
});
});
4 changes: 2 additions & 2 deletions __tests__/setup.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ describe('setup', () => {
'localStorage',
'_sessionStorage',
'sessionStorage',
].forEach(globalKey => {
].forEach((globalKey) => {
if (restore) {
delete global[globalKey];
global[globalKey] = orignalImpGlobsl[globalKey];
Expand All @@ -31,7 +31,7 @@ describe('setup', () => {
restoreGlobals();
});

['_localStorage', '_sessionStorage'].forEach(gKey => {
['_localStorage', '_sessionStorage'].forEach((gKey) => {
it(`[${gKey}] should define a property on the global object with writable false`, () => {
require('../src/setup');
expect(global[gKey.replace('_', '')].constructor.name).toBe(
Expand Down
8 changes: 4 additions & 4 deletions src/localstorage.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ export class LocalStorage {
constructor(jest) {
Object.defineProperty(this, 'getItem', {
enumerable: false,
value: jest.fn(key => this[key] !== undefined ? this[key] : null),
value: jest.fn((key) => (this[key] !== undefined ? this[key] : null)),
});
Object.defineProperty(this, 'setItem', {
enumerable: false,
Expand All @@ -13,14 +13,14 @@ export class LocalStorage {
});
Object.defineProperty(this, 'removeItem', {
enumerable: false,
value: jest.fn(key => {
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.keys(this).map((key) => delete this[key]);
}),
});
Object.defineProperty(this, 'toString', {
Expand All @@ -31,7 +31,7 @@ export class LocalStorage {
});
Object.defineProperty(this, 'key', {
enumerable: false,
value: jest.fn(idx => Object.keys(this)[idx] || null),
value: jest.fn((idx) => Object.keys(this)[idx] || null),
});
} // end constructor

Expand Down

0 comments on commit 5ad2dde

Please sign in to comment.