forked from guilhermechapiewski/titanium-cache
-
Notifications
You must be signed in to change notification settings - Fork 1
/
cache_tests.js
58 lines (42 loc) · 1.5 KB
/
cache_tests.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
(function(){
var cache = Ti.App.Cache;
describe('cache', function() {
it('should cache objects', function() {
cache.del('my_fake_key');
expect(cache.get('my_fake_key')).toBeNull();
var obj = { my: 'obj' };
cache.put('my_fake_key', obj);
cached_obj = cache.get('my_fake_key');
expect(cached_obj).not.toBeNull();
expect(cached_obj).toEqual(obj);
});
it('should delete items from cache', function() {
cache.del('deleted_key');
expect(cache.get('deleted_key')).toBeNull();
cache.put('deleted_key', { deleted: 'obj' });
expect(cache.get('deleted_key')).not.toBeNull();
cache.del('deleted_key');
expect(cache.get('deleted_key')).toBeNull();
});
it('should get javascript objects from cache', function() {
cache.del('my_cache_key');
expect(cache.get('my_cache_key')).toBeNull();
var obj = { prop: 'value', other_prop: 'other value' };
cache.put('my_cache_key', obj);
cached_obj = cache.get('my_cache_key');
expect(cached_obj).not.toBeNull();
expect(cached_obj).toEqual(obj);
expect(cached_obj.prop).toEqual(obj.prop);
expect(cached_obj.other_prop).toEqual(obj.other_prop);
});
it('should get string objects from cache', function() {
cache.del('my_cache_key');
expect(cache.get('my_cache_key')).toBeNull();
var obj = '<my_xml>hello world</my_xml>';
cache.put('my_cache_key', obj);
cached_obj = cache.get('my_cache_key');
expect(cached_obj).not.toBeNull();
expect(cached_obj).toEqual(obj);
});
});
})();