expect().toThrow(): support checking properties

オープン
#6,805 コメント 1 件 リアクション 0 件 担当者 0 名 GitHub で見る

メンテナーはふだん 1 日以内に返信

まだ誰も着手していません。

評価

難易度
4/5
見積もり時間
3〜5日
初心者へのやさしさ
35/100
issue の種類
機能追加
明瞭さ
おおむね明確
活発さ
停滞
技術スタック
typescript
領域
testing

調査の方向性

まず expect().toThrow() の実装と、その matcher のテストを見つけます。要求されている Error プロパティのチェックと、callback または返されたエラーを使う代替案を比較し、メッセージの一致と cause などのプロパティのチェックをカバーするテストによって、サポートする動作を 1 つ定義します。

索引モデルが issue の本文から書いたものです。

説明

Is your feature request related to a problem? Please describe.

I can check that something will throw but I don't see a straightforward way to check properties on the thrown exception.

Describe the solution you'd like

expect(someFn).toThrow(new Error("kaboom", { cause: new TypeError("bad input") }));

or some way to pass in a function to toThrow() or to get the thrown exception to check things:

expect(someFn).toThrow(new Error("kaboom"), (e) => {
  // more assertions, e.g. on `e.cause`
});
const thrownError = expect(someFn).toThrow(new Error("kaboom"));
// more assertions, e.g. on `thrownError.cause`

Describe alternatives you've considered

  1. Calling the function direclty myself and wrapping with try...catch (I have to remember to add an explicit fail() if the function doesn't throw, otherwise the test may pass with a false positive).
  2. Using some setup with a spy to catch the exception… not sure if that is a thing yet or not.
主要言語
TypeScript
スター
3.6k
フォーク
713
PR マージ指標
30日以内にマージされた PR はありません

環境構築

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

denoland/std のほかの issue

denoland/std の issue をすべて見る

似ている issue

TypeScript の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。