2 QUnit.module( 'mediawiki.storage' );
4 QUnit.test( 'set/get with localStorage', 3, function ( assert ) {
5 this.sandbox.stub( mw.storage, 'localStorage', {
6 setItem: this.sandbox.spy(),
7 getItem: this.sandbox.stub()
10 mw.storage.set( 'foo', 'test' );
11 assert.ok( mw.storage.localStorage.setItem.calledOnce );
13 mw.storage.localStorage.getItem.withArgs( 'foo' ).returns( 'test' );
14 mw.storage.localStorage.getItem.returns( null );
15 assert.strictEqual( mw.storage.get( 'foo' ), 'test', 'Check value gets stored.' );
16 assert.strictEqual( mw.storage.get( 'bar' ), null, 'Unset values are null.' );
19 QUnit.test( 'set/get without localStorage', 3, function ( assert ) {
20 this.sandbox.stub( mw.storage, 'localStorage', {
21 getItem: this.sandbox.stub(),
22 removeItem: this.sandbox.stub(),
23 setItem: this.sandbox.stub()
26 mw.storage.localStorage.getItem.throws();
27 assert.strictEqual( mw.storage.get( 'foo' ), false );
29 mw.storage.localStorage.setItem.throws();
30 assert.strictEqual( mw.storage.set( 'foo', 'test' ), false );
32 mw.storage.localStorage.removeItem.throws();
33 assert.strictEqual( mw.storage.remove( 'foo', 'test' ), false );