Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: increase coverage of _http_outgoing #10820

Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
60 changes: 60 additions & 0 deletions test/parallel/test-http-outgoing-proto.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,63 @@ assert.strictEqual(
typeof ClientRequest.prototype._implicitHeader, 'function');
assert.strictEqual(
typeof ServerResponse.prototype._implicitHeader, 'function');

// validateHeader
assert.throws(() => {
const outgoingMessage = new OutgoingMessage();
outgoingMessage.setHeader();
}, /^TypeError: Header name must be a valid HTTP Token \["undefined"\]$/);

assert.throws(() => {
const outgoingMessage = new OutgoingMessage();
outgoingMessage.setHeader('test');
}, /^Error: "value" required in setHeader\("test", value\)$/);

assert.throws(() => {
const outgoingMessage = new OutgoingMessage();
outgoingMessage.setHeader(404);
}, /^TypeError: Header name must be a valid HTTP Token \["404"\]$/);

assert.throws(() => {
const outgoingMessage = new OutgoingMessage();
outgoingMessage.setHeader.call({_header: 'test'}, 'test', 'value');
}, /^Error: Can't set headers after they are sent.$/);

assert.throws(() => {
const outgoingMessage = new OutgoingMessage();
outgoingMessage.setHeader('200', 'あ');
}, /^TypeError: The header content contains invalid characters$/);

// write
assert.throws(() => {
const outgoingMessage = new OutgoingMessage();
outgoingMessage.write();
}, /^Error: _implicitHeader\(\) method is not implemented$/);

assert(OutgoingMessage.prototype.write.call({_header: 'test'}));

assert.throws(() => {
const outgoingMessage = new OutgoingMessage();
outgoingMessage.write.call({_header: 'test', _hasBody: 'test'});
}, /^TypeError: First argument must be a string or Buffer$/);

assert.throws(() => {
const outgoingMessage = new OutgoingMessage();
outgoingMessage.write.call({_header: 'test', _hasBody: 'test'}, 1);
}, /^TypeError: First argument must be a string or Buffer$/);

// addTrailers
assert.throws(() => {
const outgoingMessage = new OutgoingMessage();
outgoingMessage.addTrailers();
}, /^TypeError: Cannot convert undefined or null to object$/);

assert.throws(() => {
const outgoingMessage = new OutgoingMessage();
outgoingMessage.addTrailers({'あ': 'value'});
}, /^TypeError: Trailer name must be a valid HTTP Token \["あ"\]$/);

assert.throws(() => {
const outgoingMessage = new OutgoingMessage();
outgoingMessage.addTrailers({404: 'あ'});
}, /^TypeError: The trailer content contains invalid characters$/);