storage_mock

Allows to instantiate a mock implementations of Storage, compatible to the "axGlobalStorage" injection. For the widget-specific "axStorage" injection, refer to the widget_services_storage_mock module.

Contents

Module Members

Types

Module Members

create()

Creates a storage mock that does not actually change the browser's local- or session-storage.

Returns
Type Description
StorageMock a fresh mock instance

Types

StorageMock

extends {Storage}

A mock for Storage that does not actually change the browser's local- or session-storage. Instances of this mock are compatible to the "axGlobalStorage" injection.

Do not confuse this with the {@AxStorageMock}, which is compatible to the "axStorage" injection offered by the widget services.

Note that the mock does perform JSON transformations of the value objects, just like the actual Storage.

{StorageMock}

{StorageMock}.- unknown - Object

Provides access to the backing stores of the storage mock.

Has a local and a session property, each of which has spies for getItem/setItem/removeItem. The local and session properties also provide direct access to their respective backing store objects, accessible in this manner:

import { createAxGlobalStorageMock } from 'laxar/laxar-widget-service-mocks';
const storageMock = createAxGlobalStorageMock();
storageMock.getLocalStorage( 'myNs' ).setItem( 'k', 'v' );
expect( storageMock.mockBackends.local.myNs.k ).toEqual( '"v"' );  // note the JSON transform