hapijs / hapijs/code

pass parameter to throw

Đang mở
#180 0 bình luận 0 reaction 0 người được giao Xem trên GitHub
feature
Ngôn ngữ chính
JavaScript
Star
231
Fork
75
Chỉ số merge pull request
Không có pull request nào được merge trong 30 ngày

Mô tả

#### 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.

Hướng dẫn đóng góp

Mở hướng dẫn đóng góp

Đánh giá

Issue này chưa được đánh giá.

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.