@@ -599,3 +599,113 @@ test('Set-Cookie parser', () => {
599
599
headers = new Headers ( )
600
600
assert . deepEqual ( getSetCookies ( headers ) , [ ] )
601
601
} )
602
+
603
+ test ( 'Cookie setCookie throws if headers is not of type Headers' , ( ) => {
604
+ class Headers {
605
+ [ Symbol . toStringTag ] = 'CustomHeaders'
606
+ }
607
+ const headers = new Headers ( )
608
+ assert . throws (
609
+ ( ) => {
610
+ setCookie ( headers , {
611
+ name : 'key' ,
612
+ value : 'Cat' ,
613
+ httpOnly : true ,
614
+ secure : true ,
615
+ maxAge : 3
616
+ } )
617
+ } ,
618
+ new TypeError ( 'Illegal invocation' )
619
+ )
620
+ } )
621
+
622
+ test ( 'Cookie setCookie does not throw if headers is an instance of undici owns Headers class' , ( ) => {
623
+ const headers = new Headers ( )
624
+ setCookie ( headers , {
625
+ name : 'key' ,
626
+ value : 'Cat' ,
627
+ httpOnly : true ,
628
+ secure : true ,
629
+ maxAge : 3
630
+ } )
631
+ } )
632
+
633
+ test ( 'Cookie setCookie does not throw if headers is an instance of the global Headers class' , ( ) => {
634
+ const headers = new globalThis . Headers ( )
635
+ setCookie ( headers , {
636
+ name : 'key' ,
637
+ value : 'Cat' ,
638
+ httpOnly : true ,
639
+ secure : true ,
640
+ maxAge : 3
641
+ } )
642
+ } )
643
+
644
+ test ( 'Cookie getCookies throws if headers is not of type Headers' , ( ) => {
645
+ class Headers {
646
+ [ Symbol . toStringTag ] = 'CustomHeaders'
647
+ }
648
+ const headers = new Headers ( )
649
+ assert . throws (
650
+ ( ) => {
651
+ getCookies ( headers )
652
+ } ,
653
+ new TypeError ( 'Illegal invocation' )
654
+ )
655
+ } )
656
+
657
+ test ( 'Cookie getCookies does not throw if headers is an instance of undici owns Headers class' , ( ) => {
658
+ const headers = new Headers ( )
659
+ getCookies ( headers )
660
+ } )
661
+
662
+ test ( 'Cookie getCookie does not throw if headers is an instance of the global Headers class' , ( ) => {
663
+ const headers = new globalThis . Headers ( )
664
+ getCookies ( headers )
665
+ } )
666
+
667
+ test ( 'Cookie getSetCookies throws if headers is not of type Headers' , ( ) => {
668
+ class Headers {
669
+ [ Symbol . toStringTag ] = 'CustomHeaders'
670
+ }
671
+ const headers = new Headers ( { 'set-cookie' : 'Space=Cat' } )
672
+ assert . throws (
673
+ ( ) => {
674
+ getSetCookies ( headers )
675
+ } ,
676
+ new TypeError ( 'Illegal invocation' )
677
+ )
678
+ } )
679
+
680
+ test ( 'Cookie getSetCookies does not throw if headers is an instance of undici owns Headers class' , ( ) => {
681
+ const headers = new Headers ( { 'set-cookie' : 'Space=Cat' } )
682
+ getSetCookies ( headers )
683
+ } )
684
+
685
+ test ( 'Cookie setCookie does not throw if headers is an instance of the global Headers class' , ( ) => {
686
+ const headers = new globalThis . Headers ( { 'set-cookie' : 'Space=Cat' } )
687
+ getSetCookies ( headers )
688
+ } )
689
+
690
+ test ( 'Cookie deleteCookie throws if headers is not of type Headers' , ( ) => {
691
+ class Headers {
692
+ [ Symbol . toStringTag ] = 'CustomHeaders'
693
+ }
694
+ const headers = new Headers ( )
695
+ assert . throws (
696
+ ( ) => {
697
+ deleteCookie ( headers , 'deno' )
698
+ } ,
699
+ new TypeError ( 'Illegal invocation' )
700
+ )
701
+ } )
702
+
703
+ test ( 'Cookie deleteCookie does not throw if headers is an instance of undici owns Headers class' , ( ) => {
704
+ const headers = new Headers ( )
705
+ deleteCookie ( headers , 'deno' )
706
+ } )
707
+
708
+ test ( 'Cookie getCookie does not throw if headers is an instance of the global Headers class' , ( ) => {
709
+ const headers = new globalThis . Headers ( )
710
+ deleteCookie ( headers , 'deno' )
711
+ } )
0 commit comments