Allow simpler tests for error.code
还没有人认领这个 Issue。
评估
- 难度
- 3/5
- 预计耗时
- 1-2 天
- 新手友好度
- 35/100
- Issue 类型
- 功能
- 描述清晰度
- 基本清楚
- 活跃度
- 停滞
- 技术栈
- javascript
- 领域
- testing-qa
调研方向
首先定位 throw() 和 reject() 断言的入口点,以及现有的 contain() 行为。为可选消息和提议的错误属性对象添加覆盖测试,包括 ERR_INVALID_ARG_TYPE 示例,并确认两个断言都保留当前行为。
由索引模型根据 Issue 内容生成。
描述
Support plan
- is this issue currently blocking your project? (yes/no): no
- is this issue affecting a production system? (yes/no): no
Context
- node version: any
- module version: 8.0.3
- environment (e.g. node, browser, native): node
- used with (e.g. hapi application, another framework, standalone, ...):
- any other relevant information:
What problem are you trying to solve?
To test for the .code property attached to node errors (instead of .message) that are not fixed).
Currently I have to do this manually, eg. for throw():
const Code = require('code');
const expect = Code.expect;
const err = expect(() => process.chdir(42)).to.throw(TypeError);
expect(err).to.contain({ code: 'ERR_INVALID_ARG_TYPE' });
// or as one-liner
expect(expect(() => process.chdir(42)).to.throw(TypeError)).to.contain({ code: 'ERR_INVALID_ARG_TYPE' });
Do you have a new or modified API suggestion to solve the problem?
Add a third has parameter to throw() and reject(), which takes an object which is passed to a contain() test. Also make the message optional (works since it uses a string and type must be instanceof Error). Eg.
expect(() => process.chdir(42)).to.throw(TypeError, { code: 'ERR_INVALID_ARG_TYPE' });
- 主要语言
- JavaScript
- 星标
- 231
- 派生
- 75
- PR 合并指标
- 30 天内没有已合并 PR
环境准备
- 没有 Dockerfile 或 Docker Compose 文件
- 没有 Pull Request 模板
- 阅读贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
hapijs/code 的其他 Issue
-
support
难度 3/5 1-2 天 新手友好度 38/100
-
feature
难度 5/5 一周以上 新手友好度 30/100
相似的 Issue
-
难度 2/5 1-3 小时 新手友好度 65/100
processing/p5.sound.js#123 ·
-
难度 1/5 1-3 小时 新手友好度 82/100
PhilflowIO/dav-mcp#146 ·
维护者通常 1 天内回复
-
good first issue hacktoberfest
难度 2/5 1-3 小时 新手友好度 82/100
Tanishq964/trail-kit.#4 ·
-
new icon permissions in review
难度 2/5 1-3 小时 新手友好度 62/100
simple-icons/simple-icons#15067 ·
维护者通常 1 天内回复
-
status: needs triage
难度 2/5 1-3 小时 新手友好度 62/100
mastra-ai/mastra#26562 · 1 条评论 · 1 个 reaction ·
维护者通常 1 天内回复