`examples` for property tests

Aperta
#10,971 0 commenti 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
55/100
Tipo di issue
Funzionalità
Chiarezza
Specificata chiaramente
Stato di attività
Attiva
Stack tecnologico
typescript
Ambito
testing

Direzione di ricerca

Start by locating CheckOptions and the implementations of it.prop and it.effect.prop, then trace how generated cases are checked. Add support for running supplied examples before generated cases, and consider how named examples appear in failures. Done when examples are checked by all three APIs and the behavior is covered by tests; the issue names no files or tests, so first map the relevant test entry points.

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

Descrizione

enhancement
What is the problem this feature would solve?

fast-check's examples parameter runs known inputs before the generated ones. When migrating property tests from fast-check to Arbitrary and @effect/vitest's it.prop, there's no equivalent in CheckOptions or the it.prop options.

We use examples heavily (several hundred tests) for edge cases and regression inputs that sit alongside the generated ones. Without it, each one becomes a separate it.each sharing the property's assertion:

const property = (events: ReadonlyArray<Event>, id: Id) => {
  expect(foldState(events, id)).toStrictEqual(new NotStarted())
}

it.prop("generated", [Schema.Array(Event), Id], ([events, id]) => property(events, id))

it.each([
  ["no events", [], id1],
  ["events for another review", [started], id2],
])("%s", (_name, events, id) => property(events, id))
What is the feature you are proposing to solve the problem?

An examples option on CheckOptions, and so on it.prop and it.effect.prop, that checks the given inputs before generated ones:

it.prop("not started", [Schema.Array(Event), Id], ([events, id]) => property(events, id), {
  arbitrary: {
    examples: [
      [[], id1],
      [[started], id2],
    ],
  },
})

Ideally an example could have a name, shown in the output when it fails, for example { name: "events for another review", value: [[started], id2] }. That would improve on fast-check, where we keep the names in comments.

What alternatives have you considered?

it.each alongside each property, as above. It works but doubles the boilerplate. It also separates the examples from the property they belong to, so they aren't shrunk or replayed with it.

Lingua principale
TypeScript
Stelle
16.7k
Fork
808
Merge medio
21h 22m
PR unite (30g)
486

Preparare l'ambiente

Questo progetto non fornisce container di sviluppo, Dockerfile né guida per i contributori, quindi l'ambiente è a tuo carico: parti dal suo README e consulta la nostra guida al primo contributo per i passaggi generali.

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 Effect-TS/effect

Tutte le issue di Effect-TS/effect

Issue simili

Altre issue su TypeScript

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.