forked from pixeleet/react-cookie
-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.js
62 lines (49 loc) · 1.66 KB
/
test.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
60
61
62
var reactCookie = require('./index');
describe('load', function() {
it('should not crash if cookies undefined', function() {
expect(function() {
reactCookie.setRawCookie(undefined);
}).not.toThrow();
expect(reactCookie.load('test')).toBe(undefined);
});
it('should read the cookie', function() {
reactCookie.setRawCookie('test=test');
expect(reactCookie.load('test')).toBe('test');
});
it('should parse if an object', function() {
reactCookie.setRawCookie('test={"test": true}');
expect(reactCookie.load('test').test).toBe(true);
});
it('should not parse if we ask not to', function() {
reactCookie.setRawCookie('test={"test": true}');
expect(typeof reactCookie.load('test', true)).toBe('string');
});
});
describe('save', function() {
it('should not crash if not in the browser', function() {
expect(function() {
reactCookie.save('test', 'test');
}).not.toThrow();
});
it('should update the value', function() {
reactCookie.setRawCookie('test=test');
expect(reactCookie.load('test')).toBe('test');
reactCookie.save('test', 'other');
expect(reactCookie.load('test')).not.toBe('test');
});
it('should stringify an object', function() {
reactCookie.setRawCookie('test=test');
expect(reactCookie.load('test')).toBe('test');
reactCookie.save('test', { test: true });
expect(typeof reactCookie.load('test')).toBe('object');
});
});
describe('remove', function() {
it('should do nothing if not in the browser', function() {
expect(function() {
reactCookie.remove('test');
}).not.toThrow();
});
it('should set the date in the past', function() {
});
});