hapijs / hapijs/code

Incorrect prototype check

未关闭
#182 2 条评论 1 个 reaction 已指派 0 人 在 GitHub 查看
support
主要语言
JavaScript
星标
231
派生
75
PR 合并指标
30 天内没有已合并 PR

描述

#### Support plan

* *is this issue currently blocking your project?* yes
* *is this issue affecting a production system?* no

#### Context

* *node version*: 18.x
* *module version with issue*: 9.0.3
* *last module version without issue*: NA
* *environment* (e.g. node, browser, native): node
* *used with* `@hapi/lab@25.1.2`
* *any other relevant information*: NA

#### What are you trying to achieve or the steps to reproduce?

The module does not ignore the prototype during a comparison.

```js
const Code = require('@hapi/code');

const noProto = Object.create(null);
noProto.a = Object.create(null);
noProto.a.b = 1;

Code.settings.comparePrototypes = false;
Code.expect([noProto]).to.once.include({ a: { b: 1 } });
```

** By using simple objects `{}` the comparison works as expected.

#### What was the result you got?

```
/Users/manuel_spigolon/dev/misc/hapi/code/lib/index.js:139
throw error;
^

Error: Expected [ [Object: null prototype] { a: [Object: null prototype] { b: 1 } } ] to include { a: { b: 1 } } once
at internals.Assertion.internals.include (/Users/manuel_spigolon/dev/misc/hapi/code/lib/index.js:239:17)
at Object. (/Users/manuel_spigolon/dev/misc/hapi/code/asd.js:8:32)
at Module._compile (node:internal/modules/cjs/loader:1155:14)
at Object.Module._extensions..js (node:internal/modules/cjs/loader:1209:10)
at Module.load (node:internal/modules/cjs/loader:1033:32)
at Function.Module._load (node:internal/modules/cjs/loader:868:12)
at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:81:12)
at node:internal/main/run_main_module:22:47 {
actual: undefined,
expected: undefined,
}
```

#### What result did you expect?

No error due to the default `comparePrototypes = false` setting

贡献指南

打开贡献指南

调研方向

Reproduce the failure with the provided Node example, then inspect lib/index.js around lines 139 and 239 and the comparePrototypes setting. Done means the comparison succeeds without an error for nested null-prototype objects when comparePrototypes is false.

由索引模型根据 Issue 内容生成。

评估

技术栈
javascript, node.js
领域
testing
Issue 类型
缺陷
难度
3/5
预计耗时
1-2 天
活跃度
停滞
描述清晰度
描述清楚
新手友好度
38/100

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。