GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — assert: fix throws trace · nodejs/node@e9ac468

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • lib
    • assert.js
  • test/message
    • assert_throws_stack.js
    • assert_throws_stack.out
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎lib/assert.js‎

Copy file name to clipboardExpand all lines: lib/assert.js
+15-19Lines changed: 15 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -207,11 +207,17 @@ assert.notStrictEqual = function notStrictEqual(actual, expected, message) {
207207
}
208208
};
209209

210-
function createMsg(msg, key, actual, expected) {
211-
if (msg)
212-
return msg;
213-
return `${key}: expected ${inspect(expected[key])}, ` +
214-
`not ${inspect(actual[key])}`;
210+
function compareExceptionKey(actual, expected, key, msg) {
211+
if (!isDeepStrictEqual(actual[key], expected[key])) {
212+
innerFail({
213+
actual: actual[key],
214+
expected: expected[key],
215+
message: msg || `${key}: expected ${inspect(expected[key])}, ` +
216+
`not ${inspect(actual[key])}`,
217+
operator: 'throws',
218+
stackStartFn: assert.throws
219+
});
220+
}
215221
}
216222

217223
function expectedException(actual, expected, msg) {
@@ -226,23 +232,13 @@ function expectedException(actual, expected, msg) {
226232
// The name and message could be non enumerable. Therefore test them
227233
// explicitly.
228234
if ('name' in expected) {
229-
assert.strictEqual(
230-
actual.name,
231-
expected.name,
232-
createMsg(msg, 'name', actual, expected));
235+
compareExceptionKey(actual, expected, 'name', msg);
233236
}
234237
if ('message' in expected) {
235-
assert.strictEqual(
236-
actual.message,
237-
expected.message,
238-
createMsg(msg, 'message', actual, expected));
238+
compareExceptionKey(actual, expected, 'message', msg);
239239
}
240-
const keys = Object.keys(expected);
241-
for (const key of keys) {
242-
assert.deepStrictEqual(
243-
actual[key],
244-
expected[key],
245-
createMsg(msg, key, actual, expected));
240+
for (const key of Object.keys(expected)) {
241+
compareExceptionKey(actual, expected, key, msg);
246242
}
247243
return true;
248244
}
Collapse file

‎test/message/assert_throws_stack.js‎

Copy file name to clipboard
+6Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
'use strict';
2+
3+
require('../common');
4+
const assert = require('assert').strict;
5+
6+
assert.throws(() => { throw new Error('foo'); }, { bar: true });
Collapse file

‎test/message/assert_throws_stack.out‎

Copy file name to clipboard
+14Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
assert.js:*
2+
throw new AssertionError(obj);
3+
^
4+
5+
AssertionError [ERR_ASSERTION]: bar: expected true, not undefined
6+
at Object.<anonymous> (*assert_throws_stack.js:*:*)
7+
at *
8+
at *
9+
at *
10+
at *
11+
at *
12+
at *
13+
at *
14+
at *

0 commit comments

Comments
0 (0)
You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.