@@ -4,38 +4,39 @@ const common = require('../common');
4
4
if ( ! common . hasCrypto )
5
5
common . skip ( 'missing crypto' ) ;
6
6
7
+ const assert = require ( 'assert' ) ;
7
8
const http2 = require ( 'http2' ) ;
8
9
9
10
// Verify that setTimeout callback verifications work correctly
11
+ const verifyCallbacks = ( server ) => {
12
+ const testTimeout = 10 ;
13
+ const notFunctions = [ true , 1 , { } , [ ] , null , 'test' ] ;
14
+ const invalidCallBackError = {
15
+ type : TypeError ,
16
+ code : 'ERR_INVALID_CALLBACK' ,
17
+ message : 'Callback must be a function'
18
+ } ;
10
19
20
+ notFunctions . forEach ( ( notFunction ) =>
21
+ common . expectsError (
22
+ ( ) => server . setTimeout ( testTimeout , notFunction ) ,
23
+ invalidCallBackError
24
+ )
25
+ ) ;
26
+
27
+ // No callback
28
+ const returnedVal = server . setTimeout ( testTimeout ) ;
29
+ assert . strictEqual ( returnedVal . timeout , testTimeout ) ;
30
+ } ;
31
+
32
+ // Test with server
11
33
{
12
34
const server = http2 . createServer ( ) ;
13
- common . expectsError (
14
- ( ) => server . setTimeout ( 10 , 'test' ) ,
15
- {
16
- code : 'ERR_INVALID_CALLBACK' ,
17
- type : TypeError
18
- } ) ;
19
- common . expectsError (
20
- ( ) => server . setTimeout ( 10 , 1 ) ,
21
- {
22
- code : 'ERR_INVALID_CALLBACK' ,
23
- type : TypeError
24
- } ) ;
35
+ verifyCallbacks ( server ) ;
25
36
}
26
37
38
+ // Test with secure server
27
39
{
28
- const server = http2 . createSecureServer ( { } ) ;
29
- common . expectsError (
30
- ( ) => server . setTimeout ( 10 , 'test' ) ,
31
- {
32
- code : 'ERR_INVALID_CALLBACK' ,
33
- type : TypeError
34
- } ) ;
35
- common . expectsError (
36
- ( ) => server . setTimeout ( 10 , 1 ) ,
37
- {
38
- code : 'ERR_INVALID_CALLBACK' ,
39
- type : TypeError
40
- } ) ;
40
+ const secureServer = http2 . createSecureServer ( { } ) ;
41
+ verifyCallbacks ( secureServer ) ;
41
42
}
0 commit comments