Hacktoberfest 2026:维护者为十月标记出来的 issue,仍然开放、适合新手。 浏览 Hacktoberfest issue

Allow simpler tests for error.code

未关闭
#166 2 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 Issue。

评估

难度
3/5
预计耗时
1-2 天
新手友好度
35/100
Issue 类型
功能
描述清晰度
基本清楚
活跃度
停滞
技术栈
javascript
领域
testing-qa

调研方向

首先定位 throw() 和 reject() 断言的入口点,以及现有的 contain() 行为。为可选消息和提议的错误属性对象添加覆盖测试,包括 ERR_INVALID_ARG_TYPE 示例,并确认两个断言都保留当前行为。

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

描述

feature
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 模板
  • 阅读贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

hapijs/code 的其他 Issue

查看 hapijs/code 的全部 Issue

相似的 Issue

更多 JavaScript Issue

把新 issue 发到你的邮箱

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