expect().toThrow(): support checking properties

Aperta
#6,805 1 commento 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
4/5
Tempo stimato
3-5 giorni
Idoneità per principianti
35/100
Tipo di issue
Funzionalità
Chiarezza
Abbastanza chiara
Stato di attività
Ferma
Stack tecnologico
typescript
Ambito
testing

Direzione di ricerca

Inizia individuando l’implementazione di expect().toThrow() e i test del relativo matcher. Confronta i controlli richiesti sulle proprietà di Error e le alternative con callback o errore restituito, quindi definisci un comportamento supportato con test che coprano la corrispondenza del messaggio e il controllo di proprietà come cause.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

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.
Lingua principale
TypeScript
Stelle
3.6k
Fork
713
Metriche di merge delle PR
Nessuna PR unita negli ultimi 30g

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di denoland/std

Tutte le issue di denoland/std

Issue simili

Altre issue su TypeScript

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.