diff --git a/test/parallel/test-http2-server-settimeout-no-callback.js b/test/parallel/test-http2-server-settimeout-no-callback.js index cdea67f4e87d1e..a43fbb212958c8 100644 --- a/test/parallel/test-http2-server-settimeout-no-callback.js +++ b/test/parallel/test-http2-server-settimeout-no-callback.js @@ -4,38 +4,39 @@ const common = require('../common'); if (!common.hasCrypto) common.skip('missing crypto'); +const assert = require('assert'); const http2 = require('http2'); // Verify that setTimeout callback verifications work correctly +const verifyCallbacks = (server) => { + const testTimeout = 10; + const notFunctions = [true, 1, {}, [], null, 'test']; + const invalidCallBackError = { + type: TypeError, + code: 'ERR_INVALID_CALLBACK', + message: 'Callback must be a function' + }; + notFunctions.forEach((notFunction) => + common.expectsError( + () => server.setTimeout(testTimeout, notFunction), + invalidCallBackError + ) + ); + + // No callback + const returnedVal = server.setTimeout(testTimeout); + assert.strictEqual(returnedVal.timeout, testTimeout); +}; + +// Test with server { const server = http2.createServer(); - common.expectsError( - () => server.setTimeout(10, 'test'), - { - code: 'ERR_INVALID_CALLBACK', - type: TypeError - }); - common.expectsError( - () => server.setTimeout(10, 1), - { - code: 'ERR_INVALID_CALLBACK', - type: TypeError - }); + verifyCallbacks(server); } +// Test with secure server { - const server = http2.createSecureServer({}); - common.expectsError( - () => server.setTimeout(10, 'test'), - { - code: 'ERR_INVALID_CALLBACK', - type: TypeError - }); - common.expectsError( - () => server.setTimeout(10, 1), - { - code: 'ERR_INVALID_CALLBACK', - type: TypeError - }); + const secureServer = http2.createSecureServer({}); + verifyCallbacks(secureServer); }