Title: Comparing errors through deepEqual · Issue #3122 · nodejs/node · GitHub
Open Graph Title: Comparing errors through deepEqual · Issue #3122 · nodejs/node
X Title: Comparing errors through deepEqual · Issue #3122 · nodejs/node
Description: I'm implementing tests for my js project and I need to compare an error returned from a rejected promise with an expected one. It turns out that, no mater what is the content of the error object, assert.deepEqual always returns true as l...
Open Graph Description: I'm implementing tests for my js project and I need to compare an error returned from a rejected promise with an expected one. It turns out that, no mater what is the content of the error object, a...
X Description: I'm implementing tests for my js project and I need to compare an error returned from a rejected promise with an expected one. It turns out that, no mater what is the content of the error objec...
Opengraph URL: https://github.com/nodejs/node/issues/3122
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Comparing errors through deepEqual","articleBody":"I'm implementing tests for my js project and I need to compare an error returned from a rejected promise with an expected one. \n\nIt turns out that, no mater what is the content of the error object, assert.deepEqual always returns true as long as the two instances being compared are Errors.\n\nThe same behaviour does not occur when comparing strings, for example (node version 4.1.1):\n\n```\nnode --version\nv4.1.1\n\n\u003e let assert = require(\"assert\");\nundefined\n\n\u003e assert.deepEqual(new Error(\"a\"), new Error(\"b\"));\nundefined\n\n\u003e assert.deepEqual(new String(\"a\"), new String(\"b\"));\nAssertionError: [String: 'a'] deepEqual [String: 'b']\n at repl:1:8\n at REPLServer.defaultEval (repl.js:164:27)\n at bound (domain.js:250:14)\n at REPLServer.runBound [as eval] (domain.js:263:12)\n at REPLServer.\u003canonymous\u003e (repl.js:393:12)\n at emitOne (events.js:82:20)\n at REPLServer.emit (events.js:169:7)\n at REPLServer.Interface._onLine (readline.js:210:10)\n at REPLServer.Interface._line (readline.js:549:8)\n at REPLServer.Interface._ttyWrite (readline.js:826:14)\n\n```\n\nReading the [documentation for the deepEqual assertion](https://nodejs.org/api/assert.html#assert_assert_deepequal_actual_expected_message), I didn't found any mentions regarding something special when comparing Errors.\n\nIs this behaviour intended by design? Am I missing something important or should a consider another strategy to deeply compare two Error objects (instances + messages)?\n","author":{"url":"https://github.com/rpepato","@type":"Person","name":"rpepato"},"datePublished":"2015-09-30T01:07:44.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":3},"url":"https://github.com/3122/node/issues/3122"}
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:33c9e9e8-18b7-36f4-90b6-c6d5642a418b |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | A72E:2B4DA:145476A:1C40EE9:6A4DEC9F |
| html-safe-nonce | 5045a17eb502935dd1377a502bc1573d1ce876448743a1dfd5d8cfff632a4911 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJBNzJFOjJCNERBOjE0NTQ3NkE6MUM0MEVFOTo2QTRERUM5RiIsInZpc2l0b3JfaWQiOiIzNjM4NTc2Nzc4ODk5NzQ1OTUxIiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0= |
| visitor-hmac | 4df4d535d996c66ba2e736f112ecf245a76007e8e5d955d5024ba55a3d9ccb95 |
| hovercard-subject-tag | issue:108990489 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/nodejs/node/3122/issue_layout |
| twitter:image | https://opengraph.githubassets.com/90b979f7cc9fe18686f74a7ae08d8187811c4c531d4e330bf88c4d91f07dbc3d/nodejs/node/issues/3122 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/90b979f7cc9fe18686f74a7ae08d8187811c4c531d4e330bf88c4d91f07dbc3d/nodejs/node/issues/3122 |
| og:image:alt | I'm implementing tests for my js project and I need to compare an error returned from a rejected promise with an expected one. It turns out that, no mater what is the content of the error object, a... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | rpepato |
| hostname | github.com |
| expected-hostname | github.com |
| None | 06b8a6144231bf3a234f1c2e9993861e07ce98a905912b114aa386c2d7e84b33 |
| turbo-cache-control | no-preview |
| go-import | github.com/nodejs/node git https://github.com/nodejs/node.git |
| octolytics-dimension-user_id | 9950313 |
| octolytics-dimension-user_login | nodejs |
| octolytics-dimension-repository_id | 27193779 |
| octolytics-dimension-repository_nwo | nodejs/node |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 27193779 |
| octolytics-dimension-repository_network_root_nwo | nodejs/node |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 1d344bdb7547fe6bca17a59bb2b8aac3dc9532a0 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width