@@ -24,13 +24,6 @@ test('empty value', 1, function () {
2424 equal ( $ . cookie ( 'c' ) , '' , 'should return value' ) ;
2525} ) ;
2626
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-
3427test ( 'not existing' , 1 , function ( ) {
3528 equal ( $ . cookie ( 'whatever' ) , null , 'should return null' ) ;
3629} ) ;
@@ -84,24 +77,32 @@ test('number', 1, function () {
8477 equal ( $ . cookie ( 'c' ) , '1234' , 'should write value' ) ;
8578} ) ;
8679
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' ) ;
9185} ) ;
9286
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 ( ) {
9495 var yesterday = new Date ( ) ;
9596 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' ) ;
9899} ) ;
99100
100101test ( 'return value' , 1 , function ( ) {
101102 equal ( $ . cookie ( 'c' , 'v' ) , 'c=v' , 'should return written cookie string' ) ;
102103} ) ;
103104
104- test ( 'raw: true' , 1 , function ( ) {
105+ test ( 'raw option set to true' , 1 , function ( ) {
105106 equal ( $ . cookie ( 'c' , ' v' , { raw : true } ) . split ( '=' ) [ 1 ] ,
106107 ' v' , 'should not encode' ) ;
107108} ) ;
0 commit comments