mock-webstorage

1.1.0 • Public • Published

MockWebStorage

GitHub license npm version CircleCI Status Greenkeeper badge

This module exports a class implementing the Storage interface. No persistence strategy is built-in. This class is suitable for use as a localStorage or sessionStorage mock in unit tests.

To access or set data on the storage instance, you must use the getItem and setItem methods. The ability to access arbitrary properties on the native localStorage object is not supported by this class.

Usage Examples

If you had a file "fileToTest.js" which expected localStorage to be present as a global, then you could test it in nodejs like this:

var assert = require('assert');
var MockWebStorage = require('mock-webstorage');
global.localStorage = new MockWebStorage();
 
require('./fileToTest');
 
assert.strictEqual(localStorage.getItem('foo'), 'bar');

Types

Both TypeScript and Flow type definitions for this module are included! The type definitions won't require any configuration to use.

Package Sidebar

Install

npm i mock-webstorage

Weekly Downloads

304

Version

1.1.0

License

MIT

Unpacked Size

11.1 kB

Total Files

10

Last publish

Collaborators

  • macil