1 |
|
2 | 'use strict';
|
3 |
|
4 | describe('localStorageMemory()', function () {
|
5 | beforeEach(function() {
|
6 | localStorageMemory.clear();
|
7 | });
|
8 | describe('localStorageMemory.getItem("foo")', function () {
|
9 | describe('"foo" has been set before', function () {
|
10 | beforeEach(function() {
|
11 | localStorageMemory.setItem('foo', 'bar');
|
12 | });
|
13 |
|
14 | it('returns true', function () {
|
15 | expect(localStorageMemory.getItem('foo')).to.be('bar');
|
16 | });
|
17 | });
|
18 | describe('foo has not been set before', function () {
|
19 | it('returns null', function () {
|
20 | expect(localStorageMemory.getItem('foo')).to.be(null);
|
21 | });
|
22 | });
|
23 | });
|
24 | describe('localStorageMemory.setItem(123, 456)', function () {
|
25 | it('stores key & value as string', function () {
|
26 | localStorageMemory.setItem(123, null);
|
27 | expect(localStorageMemory.getItem('123')).to.be('null');
|
28 | });
|
29 | });
|
30 | describe('localStorageMemory.removeItem(123)', function () {
|
31 | it('removes item "123"', function() {
|
32 | localStorageMemory.setItem('123', 'foo');
|
33 | localStorageMemory.removeItem(123);
|
34 | expect(localStorageMemory.getItem(123)).to.be(null);
|
35 | });
|
36 | });
|
37 | describe('localStorageMemory.key(0)', function () {
|
38 | describe('"foo" has been set before as only item', function () {
|
39 | beforeEach(function() {
|
40 | localStorageMemory.setItem('foo', 'bar');
|
41 | });
|
42 |
|
43 | it('returns foo', function () {
|
44 | expect(localStorageMemory.key(0)).to.be('foo');
|
45 | });
|
46 | });
|
47 | describe('no item has been set', function () {
|
48 | it('returns null', function () {
|
49 | expect(localStorageMemory.key(0)).to.be(null);
|
50 | });
|
51 | });
|
52 | });
|
53 | describe('localStorageMemory.clear()', function () {
|
54 | it('removes all items', function() {
|
55 | localStorageMemory.setItem('123', 'foo');
|
56 | localStorageMemory.setItem(456, 'bar');
|
57 | localStorageMemory.clear();
|
58 | expect(localStorageMemory.length).to.be(0);
|
59 | expect(localStorageMemory.getItem(123)).to.be(null);
|
60 | expect(localStorageMemory.getItem(456)).to.be(null);
|
61 | });
|
62 | });
|
63 | describe('localStorageMemory.length', function () {
|
64 | it ('duplicate puts don\'t increase length', function () {
|
65 | localStorageMemory.setItem('123', 'foo');
|
66 | localStorageMemory.setItem('123', 'foo');
|
67 | expect(localStorageMemory.length).to.be(1);
|
68 | });
|
69 | it ('remove non-existent item doesn\'t decrease length', function () {
|
70 | localStorageMemory.setItem('123', 'foo');
|
71 | localStorageMemory.removeItem('abc');
|
72 | expect(localStorageMemory.length).to.be(1);
|
73 | });
|
74 | });
|
75 | });
|