hapijs / hapijs/code

pass parameter to throw

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

描述

#### 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*: > 18.13.0
* *module version*: ^9.02
* *environment* (e.g. node, browser, native): node
* *used with* (e.g. hapi application, another framework, standalone, ...): hapi
* *any other relevant information*:

#### What problem are you trying to solve?

I am testing a function that requires me to pass a parameter to it. In certain cases it will throw an Error. I am unable to test this function without making a wrapper for it.

```js
const foo = (message) => {
throw Error(message)
}

let msg = "sup hapi devs"
expect(foo(msg)).to.throw(msg) // Epic fail

const wrapper = () => foo(msg)
expect(wrapper).to.throw(msg) // Success!
```

#### Do you have a new or modified API suggestion to solve the problem?
I'll look into it, just wanted to see if this concern is legitimate.

贡献指南

打开贡献指南

调研方向

首先查看 issue 中的 JavaScript 示例以及用于抛出错误的 assertion API。确定如何在不使用 wrapper 的情况下实现参数化的 throw assertion,然后添加覆盖测试,展示所请求的用法并确认预期的错误消息。

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

评估

技术栈
javascript
领域
testing
Issue 类型
功能
难度
5/5
预计耗时
一周以上
活跃度
停滞
描述清晰度
基本清楚
新手友好度
30/100

把新 issue 发到你的邮箱

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