`examples` for property tests

Abierto
#10,971 0 comentarios 0 reacciones 0 asignados Ver en GitHub

Los mantenedores suelen responder en 1 día

Nadie ha tomado este issue todavía.

Evaluación

Dificultad
4/5
Tiempo estimado
3-5 días
Aptitud para principiantes
55/100
Tipo de issue
Nueva funcionalidad
Claridad
Bien especificado
Estado de actividad
Activo
Stack tecnológico
typescript
Área
testing

Línea de trabajo

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.

Escrito por el modelo de indexación a partir del texto del issue.

Descripción

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.

Lenguaje dominante
TypeScript
Estrellas
16.7k
Forks
808
Merge medio
21 h 22 min
PR fusionados (30 d)
486

Preparar el entorno

Este proyecto no incluye contenedor de desarrollo, Dockerfile ni guía de contribución, así que la configuración corre por tu cuenta: empieza por su README y consulta nuestra guía para la primera contribución para los pasos generales.

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Más de Effect-TS/effect

Todos los issues de Effect-TS/effect

Issues similares

Más issues de TypeScript

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.