@@ -12,6 +12,7 @@ describe('Koa Session', function(){
1212 app . keys = [ 'a' , 'b' ] ;
1313 app . use ( session ( ) ) ;
1414 app . use ( function * ( ) {
15+ this . session . message = 'hi' ;
1516 this . body = this . session ;
1617 } ) ;
1718
@@ -26,7 +27,8 @@ describe('Koa Session', function(){
2627 var app = koa ( ) ;
2728 app . use ( session ( ) ) ;
2829 app . use ( function * ( ) {
29- this . session ;
30+ this . session . message = 'hi' ;
31+ this . body = this . session ;
3032 } ) ;
3133
3234 request ( app . listen ( ) )
@@ -44,6 +46,7 @@ describe('Koa Session', function(){
4446 signed : false
4547 } ) ) ;
4648 app . use ( function * ( ) {
49+ this . session . message = 'hi' ;
4750 this . body = this . session ;
4851 } ) ;
4952
@@ -97,7 +100,24 @@ describe('Koa Session', function(){
97100 } )
98101 } )
99102
100- describe ( 'when accessed' , function ( done ) {
103+ describe ( 'when accessed and not populated' , function ( done ) {
104+ it ( 'should not Set-Cookie' , function ( done ) {
105+ var app = App ( ) ;
106+ app . use ( function * ( ) {
107+ this . session ;
108+ this . body = 'greetings' ;
109+ } )
110+ request ( app . listen ( ) )
111+ . get ( '/' )
112+ . expect ( 200 , function ( err , res ) {
113+ if ( err ) return done ( err ) ;
114+ res . header . should . not . have . property ( 'set-cookie' ) ;
115+ done ( ) ;
116+ } )
117+ } )
118+ } )
119+
120+ describe ( 'when populated' , function ( done ) {
101121 it ( 'should Set-Cookie' , function ( done ) {
102122 var app = App ( ) ;
103123 app . use ( function * ( ) {
@@ -115,17 +135,16 @@ describe('Koa Session', function(){
115135 } )
116136 } )
117137
118- it ( 'should not set .isNew ' , function ( done ) {
138+ it ( 'should not Set-Cookie ' , function ( done ) {
119139 var app = App ( ) ;
120140 app . use ( function * ( ) {
121141 this . body = this . session ;
122142 } )
123143 request ( app . listen ( ) )
124144 . get ( '/' )
125- . expect ( 'Set-Cookie' , / k o a : s e s s / )
126145 . expect ( 200 , function ( err , res ) {
127146 if ( err ) return done ( err ) ;
128- res . header [ 'set-cookie' ] . should . not . match ( / i s N e w / ) ;
147+ res . header . should . not . have . property ( 'set-cookie' ) ;
129148 done ( ) ;
130149 } )
131150 } )
@@ -212,6 +231,23 @@ describe('Koa Session', function(){
212231 } )
213232
214233 describe ( '{}' , function ( ) {
234+ it ( 'should not Set-Cookie' , function ( done ) {
235+ var app = App ( ) ;
236+ app . use ( function * ( ) {
237+ this . session = { } ;
238+ this . body = 'asdf' ;
239+ } )
240+ request ( app . listen ( ) )
241+ . get ( '/' )
242+ . expect ( 200 , function ( err , res ) {
243+ if ( err ) return done ( err ) ;
244+ res . header . should . not . have . property ( 'set-cookie' ) ;
245+ done ( ) ;
246+ } ) ;
247+ } )
248+ } )
249+
250+ describe ( '{a: b}' , function ( ) {
215251 it ( 'should create a session' , function ( done ) {
216252 var app = App ( ) ;
217253 app . use ( function * ( ) {
0 commit comments