Add `partialDeepEqual()` in strict assertion mode
还没有人认领这个 Issue。
- 主要语言
- JavaScript
- 星标
- 122k
- 派生
- 37.4k
- 平均合并
- 4 天 3 小时
- 30 天内合并 PR
- 272
描述
What is the problem this feature will solve?
I use strict assertion mode in my tests:
import assert from "node:assert/strict";
assert.equal("...", "...");
assert.deepEqual({ "..." }, { "..." });
assert.partialDeepEqual({ "..." }, { "..." });
But the partialDeepEqual() doesn't exist. You have to use partialDeepStrictEqual() that has the word Strict in its name, whereas the other methods do not.
What is the feature you are proposing to solve the problem?
The "node:assert/strict" module should re-export partialDeepStrictEqual() with the name partialDeepEqual() so that function names are consistent in strict assertion mode.
Additional information
The partialDeepStrictEqual() function was added with https://github.com/nodejs/node/pull/54630. I couldn't find any references to the terms strict assertion mode.
"Re-export" takes place in two locations:
-
Probably for
import assert from "node:assert/strict"
https://github.com/nodejs/node/blob/56aba88702b3a7da4a44688664ff22d8afebb267/lib/assert.js#L126-L131 -
Probably for
import { strict as assert } from "node:assert"
https://github.com/nodejs/node/blob/56aba88702b3a7da4a44688664ff22d8afebb267/lib/assert.js#L894-L899
I don't think adding the following two lines is enough?
// if (options.strict) {
this.partialDeepEqual = this.partialDeepStrictEqual;
// assert.strict = ObjectAssign(strict, assert, {
partialDeepEqual: assert.partialDeepStrictEqual,
Because partialDeepEqual() doesn't exist in legacy assertion mode. So we need to manage the fact that the Assert type will be different between the two modes.
贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
调研方向
从 lib/assert.js 中 126-131 行和 894-899 行附近的两个导出位置开始,检查 strict 和 legacy 断言模式如何公开 Assert 类型。添加 strict 模式别名,但不要将其添加到 legacy 模式,然后验证两种导入形式都公开 partialDeepEqual,同时 partialDeepStrictEqual 仍然可用。
由索引模型根据 Issue 内容生成。
评估
- 技术栈
- javascript
- 领域
- api
- Issue 类型
- 功能
- 难度
- 3/5
- 预计耗时
- 1-2 天
- 活跃度
- 冷清
- 描述清晰度
- 基本清楚
- 新手友好度
- 68/100