@@ -341,4 +341,43 @@ describe('assertions', function () {
341
341
} ) . should . throw ( 'expected cookie \'name2\' to have value \'value\' but got \'value2\'' ) ;
342
342
343
343
} ) ;
344
+
345
+ it ( '#cookie (agent)' , function ( ) {
346
+ var agent = chai . request . agent ( ) ;
347
+ var cookies = [
348
+ 'name=value' ,
349
+ 'name2=value2; Expires=Wed, 09 Jun 2021 10:18:14 GMT' ,
350
+ 'name3=value3; Domain=.somedomain.com' ,
351
+ ] ;
352
+ if ( agent . jar ) // Using superagent.Agent (node)
353
+ agent . jar . setCookies ( cookies ) ;
354
+ else // using superagent.Request (browser)
355
+ agent . set ( 'set-cookie' , cookies ) ;
356
+
357
+ agent . should . have . cookie ( 'name' ) ;
358
+ agent . should . have . cookie ( 'name2' ) ;
359
+ agent . should . have . cookie ( 'name3' ) ;
360
+ agent . should . have . cookie ( 'name' , 'value' ) ;
361
+ agent . should . have . cookie ( 'name2' , 'value2' ) ;
362
+ agent . should . have . cookie ( 'name3' , 'value3' ) ;
363
+ agent . should . not . have . cookie ( 'bar' ) ;
364
+ agent . should . not . have . cookie ( 'name2' , 'bar' ) ;
365
+
366
+ ( function ( ) {
367
+ agent . should . not . have . cookie ( 'name' ) ;
368
+ } ) . should . throw ( 'expected cookie \'name\' to not exist' ) ;
369
+
370
+ ( function ( ) {
371
+ agent . should . have . cookie ( 'foo' ) ;
372
+ } ) . should . throw ( 'expected cookie \'foo\' to exist' ) ;
373
+
374
+ ( function ( ) {
375
+ agent . should . not . have . cookie ( 'name' , 'value' ) ;
376
+ } ) . should . throw ( 'expected cookie \'name\' to not have value \'value\'' ) ;
377
+
378
+ ( function ( ) {
379
+ agent . should . have . cookie ( 'name2' , 'value' ) ;
380
+ } ) . should . throw ( 'expected cookie \'name2\' to have value \'value\' but got \'value2\'' ) ;
381
+
382
+ } ) ;
344
383
} ) ;
0 commit comments