Hacktoberfest 2026: los issues que los mantenedores marcaron para octubre, abiertos y aptos para principiantes. Explorar issues de Hacktoberfest

Setup for custom queries clashes with AllByAttribute type

Abierto
#804 0 comentarios 0 reacciones 0 asignados Ver en GitHub

Nadie ha tomado este issue todavía.

Evaluación

Dificultad
2/5
Tiempo estimado
1-3 horas
Aptitud para principiantes
48/100
Tipo de issue
Documentación
Claridad
Bastante claro
Estado de actividad
Estancado
Stack tecnológico
typescript

Línea de trabajo

Comienza con la página de configuración de consultas personalizadas enlazada en el issue y compara su ejemplo de JavaScript con la conversión a TypeScript indicada. Actualiza el ejemplo para que la consulta personalizada se ajuste al tipo documentado y al uso de buildQueries; después, verifica que la versión de TypeScript ya no produzca el error de tipos indicado.

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

Descripción

Describe the bug
https://testing-library.com/docs/react-testing-library/setup#add-custom-queries

Existing setup for custom queries documentation does not work with typescript

To Reproduce
converting the following to typescript

const queryAllByDataCy = (...args) =>
  queryHelpers.queryAllByAttribute('data-cy', ...args)
const queryAllByDataCy: AllByAttribute = (_, ...args) =>
  queryHelpers.queryAllByAttribute('data-cy', ...args)

Produces a type error in the buildQueries function
type error

Argument of type 'AllByAttribute' is not assignable to parameter of type 'GetAllBy<[container: HTMLElement, id: Matcher, options?: MatcherOptions | undefined]>'.                                                                   
  Types of parameters 'attribute' and 'container' are incompatible.                                                                                                                                                                                                               
    Type 'HTMLElement' is not assignable to type 'string'.                                                                                                                                                                                                                        
                                                                                                                                                                                                                                                                                  
buildQueries(queryAllByDataCy, getMultipleError, getMissingError) 

Expected behavior
When converting the provided example to typescript the setup example should be in a format that conforms to the libraries type AllByAttribute.

This can be done by using partial application the container argument on queryHelpers.queryAllByAttribute and then updating the type of AllByAttribute to omit the partial argument
e.g.

js only:

const queryAllByDataCy = queryHelpers.queryAllByAttribute,bind(null, 'data-cy')

ts only:

type QueryAllByDataCy = (
  container: HTMLElement,
  id: Matcher,
  options?: MatcherOptions
 ) => HTMLElement[]

const queryAllByDataCy: QueryAllByDataCy = queryHelpers.queryAllByAttribute,bind(null, 'data-cy')

Screenshots
If applicable, add screenshots to help explain your problem.

Desktop (please complete the following information):

  • OS: Ubuntu 20.04.2 LTS
  • Typescript ^4.2.4
  • Node 15.14.0
Lenguaje dominante
JavaScript
Estrellas
479
Forks
738
Métricas de merge de PR
Sin PR fusionados en 30 d

Preparar el entorno

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 testing-library/testing-library-docs

Todos los issues de testing-library/testing-library-docs

Issues similares

Más issues de JavaScript

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.