node/test/parallel/test-http2-util-assert-valid-pseudoheader.js
davidmarkclements add1c02bda errors: alter ERR_HTTP2_INVALID_PSEUDOHEADER
changes the base instance for ERR_HTTP2_INVALID_PSEUDOHEADER
from Error to TypeError as a more accurate representation
of the error.

PR-URL: https://github.com/nodejs/node/pull/19808
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
Reviewed-By: Trivikram Kamat <trivikr.dev@gmail.com>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
2018-04-09 13:05:35 +02:00

32 lines
889 B
JavaScript

// Flags: --expose-internals
'use strict';
const common = require('../common');
// Tests the assertValidPseudoHeader function that is used within the
// mapToHeaders function. The assert function is not exported so we
// have to test it through mapToHeaders
const { mapToHeaders } = require('internal/http2/util');
const assert = require('assert');
function isNotError(val) {
assert(!(val instanceof Error));
}
function isError(val) {
common.expectsError({
code: 'ERR_HTTP2_INVALID_PSEUDOHEADER',
type: TypeError,
message: '":foo" is an invalid pseudoheader or is used incorrectly'
})(val);
}
isNotError(mapToHeaders({ ':status': 'a' }));
isNotError(mapToHeaders({ ':path': 'a' }));
isNotError(mapToHeaders({ ':authority': 'a' }));
isNotError(mapToHeaders({ ':scheme': 'a' }));
isNotError(mapToHeaders({ ':method': 'a' }));
isError(mapToHeaders({ ':foo': 'a' }));