1.2.1 • Published 6 years ago

lsmock v1.2.1

Weekly downloads
4
License
ISC
Repository
github
Last release
6 years ago

lsMock

Simple library used to mock out localStorage with full functionality for use in test environments or other situations where localStorage is not supported.

Setup

Install:

npm i --save lsmock

Include:

const mock = require('lsmock');

or

import mock from 'lsmock';

Usage

For use in testing suites where localStorage isn't defined, you could use lsmock something like this:

const mock = require('lsmock');
window.localStorage = new mock();

Otherwise, localStorage can be defined in the local scope if desired:

let localStorage = new lsmock();

localStorage.setItem("foo", "bar");

const test = localStorage.getItem("foo");

As with the web API, you can also access elements directly:

const test = localStorage.foo;

In the case where your tests expect localStorage to be in some initial state, that can be set as well:

let localStorage = new lsmock({
	"foo": "bar",
	"hello": "world"
});

console.log(localStorage.getItem("hello"));
1.2.1

6 years ago

1.2.0

6 years ago

1.1.4

6 years ago

1.1.3

6 years ago

1.1.2

6 years ago

1.1.1

6 years ago

1.1.0

6 years ago

1.0.1

6 years ago

1.0.0

6 years ago