Closed
Description
- Version: v11.4.0
- Platform: macOS
- Subsystem: assert
$ cat t.js
const assert = require('assert');
function StorageObject() {}
StorageObject.prototype = Object.create(null);
assert.deepStrictEqual(new StorageObject(), {});
$ node t.js
assert.js:86
throw new AssertionError(obj);
^
AssertionError [ERR_ASSERTION]: Values identical but not reference-equal:
{}
at Object.<anonymous> (/Users/luigi/t.js:6:8)
at Module._compile (internal/modules/cjs/loader.js:723:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:734:10)
at Module.load (internal/modules/cjs/loader.js:620:32)
at tryModuleLoad (internal/modules/cjs/loader.js:560:12)
at Function.Module._load (internal/modules/cjs/loader.js:552:3)
at Function.Module.runMain (internal/modules/cjs/loader.js:776:12)
at executeUserCode (internal/bootstrap/node.js:342:17)
at startExecution (internal/bootstrap/node.js:276:5)
at startup (internal/bootstrap/node.js:227:5)
The assertion fails because the objects have a different prototype. The same assertion produces a different message in other cases, for example:
$ cat t.js
const assert = require('assert');
assert.deepStrictEqual(Object.create(null), {});
$ node t.js
assert.js:86
throw new AssertionError(obj);
^
AssertionError [ERR_ASSERTION]: Expected values to be strictly deep-equal:
+ actual - expected
+ [Object: null prototype] {}
- {}
at Object.<anonymous> (/Users/luigi/t.js:3:8)
at Module._compile (internal/modules/cjs/loader.js:723:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:734:10)
at Module.load (internal/modules/cjs/loader.js:620:32)
at tryModuleLoad (internal/modules/cjs/loader.js:560:12)
at Function.Module._load (internal/modules/cjs/loader.js:552:3)
at Function.Module.runMain (internal/modules/cjs/loader.js:776:12)
at executeUserCode (internal/bootstrap/node.js:342:17)
at startExecution (internal/bootstrap/node.js:276:5)
at startup (internal/bootstrap/node.js:227:5)
cc: @BridgeAR