Skip to content

Commit 52e1faa

Browse files
committed
* added tests for expiry
1 parent 1fa4a18 commit 52e1faa

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

test.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,13 @@ test('empty value', 1, function () {
2020
equal($.cookie('c'), '', 'should return value');
2121
});
2222

23+
test('simple value with expires', 1, function () {
24+
var tomorrow = new Date();
25+
tomorrow.setDate(tomorrow.getDate() + 5);
26+
document.cookie = 'c=testcookie; expires=' + tomorrow.toUTCString();
27+
equal($.cookie('c'), 'testcookie', 'should return value');
28+
});
29+
2330
test('not existing', 1, function () {
2431
equal($.cookie('whatever'), null, 'should return null');
2532
});
@@ -57,6 +64,19 @@ test('number', 1, function() {
5764
equal($.cookie('c'), '1234', 'should write value');
5865
});
5966

67+
test('with expires 7 days from now', 1, function() {
68+
var seven_days_from_now = new Date();
69+
seven_days_from_now.setDate(seven_days_from_now.getDate() + 7);
70+
equal($.cookie('c', 'v', {expires:7}), 'c=v; expires='+seven_days_from_now.toUTCString(), 'should return the cookie string with expires');
71+
});
72+
73+
test('with expires yesterday', 2, function() {
74+
var yesterday = new Date();
75+
yesterday.setDate(yesterday.getDate() - 1);
76+
equal($.cookie('c', 'v', {expires:-1}), 'c=v; expires='+yesterday.toUTCString(), 'should return the cookie string with expires');
77+
equal(document.cookie, '', 'should not save expired cookie');
78+
});
79+
6080
test('return value', 1, function () {
6181
equal($.cookie('c', 'v'), 'c=v', 'should return written cookie string');
6282
});

0 commit comments

Comments
 (0)