@@ -24,13 +24,6 @@ test('empty value', 1, function () {
24
24
equal ( $ . cookie ( 'c' ) , '' , 'should return value' ) ;
25
25
} ) ;
26
26
27
- test ( 'simple value with expires' , 1 , function ( ) {
28
- var tomorrow = new Date ( ) ;
29
- tomorrow . setDate ( tomorrow . getDate ( ) + 5 ) ;
30
- document . cookie = 'c=testcookie; expires=' + tomorrow . toUTCString ( ) ;
31
- equal ( $ . cookie ( 'c' ) , 'testcookie' , 'should return value' ) ;
32
- } ) ;
33
-
34
27
test ( 'not existing' , 1 , function ( ) {
35
28
equal ( $ . cookie ( 'whatever' ) , null , 'should return null' ) ;
36
29
} ) ;
@@ -84,24 +77,32 @@ test('number', 1, function () {
84
77
equal ( $ . cookie ( 'c' ) , '1234' , 'should write value' ) ;
85
78
} ) ;
86
79
87
- test ( 'with expires 7 days from now' , 1 , function ( ) {
88
- var seven_days_from_now = new Date ( ) ;
89
- seven_days_from_now . setDate ( seven_days_from_now . getDate ( ) + 7 ) ;
90
- equal ( $ . cookie ( 'c' , 'v' , { expires :7 } ) , 'c=v; expires=' + seven_days_from_now . toUTCString ( ) , 'should return the cookie string with expires' ) ;
80
+ test ( 'expires option as days from now' , 1 , function ( ) {
81
+ var sevenDaysFromNow = new Date ( ) ;
82
+ sevenDaysFromNow . setDate ( sevenDaysFromNow . getDate ( ) + 7 ) ;
83
+ equal ( $ . cookie ( 'c' , 'v' , { expires : 7 } ) , 'c=v; expires=' + sevenDaysFromNow . toUTCString ( ) ,
84
+ 'should write the cookie string with expires' ) ;
91
85
} ) ;
92
86
93
- test ( 'with expires yesterday' , 2 , function ( ) {
87
+ test ( 'expires option as Date instance' , 1 , function ( ) {
88
+ var sevenDaysFromNow = new Date ( ) ;
89
+ sevenDaysFromNow . setDate ( sevenDaysFromNow . getDate ( ) + 7 ) ;
90
+ equal ( $ . cookie ( 'c' , 'v' , { expires : sevenDaysFromNow } ) , 'c=v; expires=' + sevenDaysFromNow . toUTCString ( ) ,
91
+ 'should write the cookie string with expires' ) ;
92
+ } ) ;
93
+
94
+ test ( 'invalid expires option (in the past)' , 1 , function ( ) {
94
95
var yesterday = new Date ( ) ;
95
96
yesterday . setDate ( yesterday . getDate ( ) - 1 ) ;
96
- equal ( $ . cookie ( 'c' , 'v' , { expires :- 1 } ) , 'c=v; expires=' + yesterday . toUTCString ( ) , 'should return the cookie string with expires' ) ;
97
- equal ( document . cookie , '' , 'should not save expired cookie' ) ;
97
+ $ . cookie ( 'c' , 'v' , { expires : yesterday } ) ;
98
+ equal ( $ . cookie ( 'c' ) , null , 'should not save already expired cookie' ) ;
98
99
} ) ;
99
100
100
101
test ( 'return value' , 1 , function ( ) {
101
102
equal ( $ . cookie ( 'c' , 'v' ) , 'c=v' , 'should return written cookie string' ) ;
102
103
} ) ;
103
104
104
- test ( 'raw: true' , 1 , function ( ) {
105
+ test ( 'raw option set to true' , 1 , function ( ) {
105
106
equal ( $ . cookie ( 'c' , ' v' , { raw : true } ) . split ( '=' ) [ 1 ] ,
106
107
' v' , 'should not encode' ) ;
107
108
} ) ;
0 commit comments