(options)
| 248 | |
| 249 | class AssertionError extends Error { |
| 250 | constructor(options) { |
| 251 | validateObject(options, 'options'); |
| 252 | const { |
| 253 | message, |
| 254 | operator, |
| 255 | stackStartFn, |
| 256 | details, |
| 257 | // Compatibility with older versions. |
| 258 | stackStartFunction, |
| 259 | diff = 'simple', |
| 260 | } = options; |
| 261 | let { |
| 262 | actual, |
| 263 | expected, |
| 264 | } = options; |
| 265 | |
| 266 | const limit = Error.stackTraceLimit; |
| 267 | if (isErrorStackTraceLimitWritable()) Error.stackTraceLimit = 0; |
| 268 | |
| 269 | if (message != null) { |
| 270 | if (kMethodsWithCustomMessageDiff.has(operator)) { |
| 271 | super(createErrDiff(actual, expected, operator, message, diff)); |
| 272 | } else { |
| 273 | super(String(message)); |
| 274 | } |
| 275 | } else { |
| 276 | // Reset colors on each call to make sure we handle dynamically set environment |
| 277 | // variables correct. |
| 278 | colors.refresh(); |
| 279 | // Prevent the error stack from being visible by duplicating the error |
| 280 | // in a very close way to the original in case both sides are actually |
| 281 | // instances of Error. |
| 282 | if (typeof actual === 'object' && actual !== null && |
| 283 | typeof expected === 'object' && expected !== null && |
| 284 | 'stack' in actual && actual instanceof Error && |
| 285 | 'stack' in expected && expected instanceof Error) { |
| 286 | actual = copyError(actual); |
| 287 | expected = copyError(expected); |
| 288 | } |
| 289 | |
| 290 | if (kMethodsWithCustomMessageDiff.has(operator)) { |
| 291 | super(createErrDiff(actual, expected, operator, message, diff)); |
| 292 | } else if (operator === 'notDeepStrictEqual' || |
| 293 | operator === 'notStrictEqual') { |
| 294 | // In case the objects are equal but the operator requires unequal, show |
| 295 | // the first object and say A equals B |
| 296 | let base = kReadableOperator[operator]; |
| 297 | const res = StringPrototypeSplit(inspectValue(actual), '\n'); |
| 298 | |
| 299 | // In case "actual" is an object or a function, it should not be |
| 300 | // reference equal. |
| 301 | if (operator === 'notStrictEqual' && |
| 302 | ((typeof actual === 'object' && actual !== null) || |
| 303 | typeof actual === 'function')) { |
| 304 | base = kReadableOperator.notStrictEqualObject; |
| 305 | } |
| 306 | |
| 307 | // Only remove lines in case it makes sense to collapse those. |
nothing calls this directly
no test coverage detected