@@ -71,12 +71,60 @@ server.listen(0, common.mustCall(() => {
71
71
assert . deepStrictEqual ( payload , ret ) ;
72
72
} ) ) ) ;
73
73
}
74
+
74
75
// Only max 2 pings at a time based on the maxOutstandingPings option
75
76
assert ( ! client . ping ( common . expectsError ( {
76
77
code : 'ERR_HTTP2_PING_CANCEL' ,
77
78
type : Error ,
78
79
message : 'HTTP2 ping cancelled'
79
80
} ) ) ) ;
81
+
82
+ // should throw if payload is not of type ArrayBufferView
83
+ {
84
+ [ 1 , true , { } , [ ] ] . forEach ( ( invalidPayload ) =>
85
+ common . expectsError (
86
+ ( ) => client . ping ( invalidPayload ) ,
87
+ {
88
+ type : TypeError ,
89
+ code : 'ERR_INVALID_ARG_TYPE' ,
90
+ message : 'The "payload" argument must be one of type' +
91
+ ' Buffer, TypedArray, or DataView'
92
+ }
93
+ )
94
+ ) ;
95
+ }
96
+
97
+ // should throw if payload length is not 8
98
+ {
99
+ const shortPayload = Buffer . from ( 'abcdefg' ) ;
100
+ const longPayload = Buffer . from ( 'abcdefghi' ) ;
101
+ [ shortPayload , longPayload ] . forEach ( ( payloadWithInvalidLength ) =>
102
+ common . expectsError (
103
+ ( ) => client . ping ( payloadWithInvalidLength ) ,
104
+ {
105
+ type : RangeError ,
106
+ code : 'ERR_HTTP2_PING_LENGTH' ,
107
+ message : 'HTTP2 ping payload must be 8 bytes'
108
+ }
109
+ )
110
+ ) ;
111
+ }
112
+
113
+ // should throw error is callback is not of type function
114
+ {
115
+ const payload = Buffer . from ( 'abcdefgh' ) ;
116
+ [ 1 , true , { } , [ ] ] . forEach ( ( invalidCallback ) =>
117
+ common . expectsError (
118
+ ( ) => client . ping ( payload , invalidCallback ) ,
119
+ {
120
+ type : TypeError ,
121
+ code : 'ERR_INVALID_CALLBACK' ,
122
+ message : 'Callback must be a function'
123
+ }
124
+ )
125
+ ) ;
126
+ }
127
+
80
128
const req = client . request ( ) ;
81
129
req . resume ( ) ;
82
130
req . on ( 'end' , common . mustCall ( ( ) => {
0 commit comments