| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent d3c2534 commit e9ac468
3 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -207,11 +207,17 @@ assert.notStrictEqual = function notStrictEqual(actual, expected, message) { | |||
| 207 | 207 | } | |
| 208 | 208 | }; | |
| 209 | 209 | ||
| 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 | + } | ||
| 215 | 221 | } | |
| 216 | 222 | ||
| 217 | 223 | function expectedException(actual, expected, msg) { | |
@@ -226,23 +232,13 @@ function expectedException(actual, expected, msg) { | |||
| 226 | 232 | // The name and message could be non enumerable. Therefore test them | |
| 227 | 233 | // explicitly. | |
| 228 | 234 | 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); | ||
| 233 | 236 | } | |
| 234 | 237 | 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); | ||
| 239 | 239 | } | |
| 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); | ||
| 246 | 242 | } | |
| 247 | 243 | return true; | |
| 248 | 244 | } | |
| Original file line number | Diff line number | Diff 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 }); | ||
| Original file line number | Diff line number | Diff 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 * | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments