-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsimple-storage-casting-spec.js
59 lines (47 loc) · 1.84 KB
/
simple-storage-casting-spec.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
require('./helpers/local-storage-mock.js');
var simpleStorage = require('../src/simple-storage.js');
describe('simpleStorage: casting', function() {
beforeEach(function() {
localStorage.clear();
});
it('should auto-cast boolean', function() {
simpleStorage.set('boolTrue', true);
expect(simpleStorage.get('boolTrue')).toBe(true);
simpleStorage.set('boolFalse', false);
expect(simpleStorage.get('boolFalse')).toBe(false);
});
it('should auto-cast integer', function() {
simpleStorage.set('int', 123);
expect(simpleStorage.get('int')).toBe(123);
});
it('should auto-cast float', function() {
simpleStorage.set('float', 12.34);
expect(simpleStorage.get('float')).toBe(12.34);
});
it('should auto-cast JSON objects', function() {
const obj = { a: 1, b: 'test', c: true };
simpleStorage.set('obj', obj);
expect(simpleStorage.get('obj')).toEqual(obj);
});
it('should auto-cast arrays', function() {
const arr = [1, 'two', false];
simpleStorage.set('arr', arr);
expect(simpleStorage.get('arr')).toEqual(arr);
});
it('should return null for null values', function() {
simpleStorage.set('null', null);
expect(simpleStorage.get('null')).toBeNull();
});
it('should return undefined for undefined values', function() {
simpleStorage.set('undefined', undefined);
expect(simpleStorage.get('undefined')).toBe(undefined);
});
it('should treat strings as strings', function() {
simpleStorage.set('string', 'hello');
expect(simpleStorage.get('string')).toBe('hello');
});
it('should not confuse strings as objects', function() {
simpleStorage.set('notAnObject', '[');
expect(simpleStorage.get('notAnObject')).toBe('[');
});
});