Skip to content

Commit 2e215f1

Browse files
TrottBridgeAR
authored andcommitted
test: fix and refactor test-http-invalid-urls
When the second argument to `assert.throws()` is a string, it is not treated as the expected error message but rather the message that the assertion should display if no error is thrown. Ths change fixes that error in `test-http-invalid-urls.js`. Instead of skipping the test when there is no crypto, the test is now run but with `http` only. `https` is skipped. Logging was fixed. Previously, errors would be written out as being in the `[object Object]` module rather than `http` or `https`. PR-URL: #15678 Reviewed-By: Luigi Pinca <[email protected]> Reviewed-By: Yuta Hiroto <[email protected]> Reviewed-By: Colin Ihrig <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Ruben Bridgewater <[email protected]>
1 parent da40050 commit 2e215f1

File tree

1 file changed

+15
-10
lines changed

1 file changed

+15
-10
lines changed

test/parallel/test-http-invalid-urls.js

+15-10
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,25 @@
1+
/* eslint-disable crypto-check */
2+
13
'use strict';
24

35
const common = require('../common');
4-
if (!common.hasCrypto)
5-
common.skip('missing crypto');
66

7-
const assert = require('assert');
87
const http = require('http');
9-
const https = require('https');
10-
const error = 'Unable to determine the domain name';
8+
const modules = { 'http': http };
9+
10+
if (common.hasCrypto) {
11+
const https = require('https');
12+
modules.https = https;
13+
}
1114

1215
function test(host) {
13-
['get', 'request'].forEach((method) => {
14-
[http, https].forEach((module) => {
15-
assert.throws(() => module[method](host, () => {
16-
throw new Error(`${module}.${method} should not connect to ${host}`);
17-
}), error);
16+
['get', 'request'].forEach((fn) => {
17+
Object.keys(modules).forEach((module) => {
18+
const doNotCall = common.mustNotCall(
19+
`${module}.${fn} should not connect to ${host}`
20+
);
21+
const throws = () => { modules[module][fn](host, doNotCall); };
22+
common.expectsError(throws, { code: 'ERR_INVALID_DOMAIN_NAME' });
1823
});
1924
});
2025
}

0 commit comments

Comments
 (0)