This repository has been archived by the owner on Jan 14, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 9
/
cookie_tests.js
64 lines (50 loc) · 1.8 KB
/
cookie_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
59
60
61
62
63
Tinytest.add("should return the cookie value for the given name.", function (test) {
document.cookie = '_sea_test_1=1';
document.cookie = '_sea_test_2';
document.cookie = '_sea_test_3=';
document.cookie = '_sea_test_4[t]=xx';
test.equal(Cookie.get('_sea_test_1'), '1');
test.equal(Cookie.get('_sea_test_2'), '');
test.equal(Cookie.get('_sea_test_3'), '');
test.equal(Cookie.get('_sea_test_4[t]'), 'xx');
});
Tinytest.add("should return undefined for non-existing name.", function (test) {
test.isUndefined(Cookie.get('_sea_test_none'));
});
Tinytest.add("should throw error for invalid name.", function (test) {
test.isUndefined(Cookie.get('_sea_test_none'));
test.throws(function(){ Cookie.get(true); });
test.throws(function(){ Cookie.get({}); });
test.throws(function(){ Cookie.get(null); });
});
Tinytest.add("should set a cookie with a given name and value.", function (test) {
Cookie.set('_sea_test_11', 'xx');
test.equal(Cookie.get('_sea_test_11'), 'xx');
Cookie.set('_sea_test_12', 'xx', { expires: -1 });
test.isUndefined(Cookie.get('_sea_test_12'));
Cookie.set('_sea_test_13', '2', {
expires: new Date(2099, 1, 1),
path: '/'
});
test.equal(Cookie.get('_sea_test_13'), '2');
Cookie.remove('_sea_test_14');
Cookie.set('_sea_test_14', '4', {
domain: document.domain,
path: '/',
secure: true
});
test.isUndefined(Cookie.get('_sea_test_14'));
});
Tinytest.add("should remove a cookie from the machine.", function (test) {
Cookie.set('_sea_test_21', 'xx');
Cookie.remove('_sea_test_21');
test.isUndefined(Cookie.get('_sea_test_21'));
Cookie.set('_sea_test_22', 'xx', {
expires: new Date(2099, 1, 1),
path: '/'
});
Cookie.remove('_sea_test_22', {
path: '/'
});
test.isUndefined(Cookie.get('_sea_test_22'));
});