Skip to content

Commit 9c3a7bf

Browse files
Trotttargos
authored andcommitted
test: make url-util-format engine agnostic
test-util-format checks the message of an error that is generated by the JavaScript engine. Error messages that change in the underlying JavaScript engine should not be breaking changes in Node.js and therefore should not cause tests to fail. Remove the message check and replace it with a check of the type of the Error object along with the absence of a `code` property. (If a `code` property were present, it would indicate that the error was coming from Node.js rather than the JavaScript engine.) This also makes this test usable without modification in the ChakraCore fork of Node.js. PR-URL: #21141 Reviewed-By: Luigi Pinca <[email protected]> Reviewed-By: Colin Ihrig <[email protected]>
1 parent c688a00 commit 9c3a7bf

File tree

1 file changed

+12
-3
lines changed

1 file changed

+12
-3
lines changed

test/parallel/test-util-format.js

+12-3
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,18 @@ assert.strictEqual(util.format(symbol), 'Symbol(foo)');
4444
assert.strictEqual(util.format('foo', symbol), 'foo Symbol(foo)');
4545
assert.strictEqual(util.format('%s', symbol), 'Symbol(foo)');
4646
assert.strictEqual(util.format('%j', symbol), 'undefined');
47-
assert.throws(function() {
48-
util.format('%d', symbol);
49-
}, /^TypeError: Cannot convert a Symbol value to a number$/);
47+
assert.throws(
48+
() => { util.format('%d', symbol); },
49+
(e) => {
50+
// The error should be a TypeError.
51+
if (!(e instanceof TypeError))
52+
return false;
53+
54+
// The error should be from the JS engine and not from Node.js.
55+
// JS engine errors do not have the `code` property.
56+
return e.code === undefined;
57+
}
58+
);
5059

5160
// Number format specifier
5261
assert.strictEqual(util.format('%d'), '%d');

0 commit comments

Comments
 (0)