pass parameter to throw
- 主要语言
- 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