Hacktoberfest 2026: die Issues, die Maintainer für den Oktober markiert haben – offen und einsteigerfreundlich. Hacktoberfest-Issues durchsuchen

Setup for custom queries clashes with AllByAttribute type

Offen
#804 0 Kommentare 0 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen

Maintainer antworten meist innerhalb von 4 Tagen

Dieses Issue hat noch niemand übernommen.

Bewertung

Schwierigkeit
2/5
Geschätzter Aufwand
1-3 Stunden
Anfängerfreundlichkeit
48/100
Issue-Typ
Dokumentation
Klarheit
Größtenteils klar
Aktivitätsstatus
Veraltet
Tech-Stack
typescript
Bereich
documentation

Rechercherichtung

Beginne mit der im Issue verlinkten Seite zur Einrichtung benutzerdefinierter Abfragen und vergleiche deren JavaScript-Beispiel mit der gemeldeten TypeScript-Konvertierung. Aktualisiere das Beispiel so, dass die benutzerdefinierte Abfrage dem dokumentierten Typ und der Verwendung von buildQueries entspricht, und überprüfe anschließend, dass die TypeScript-Version den gemeldeten Typfehler nicht mehr erzeugt.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Beschreibung

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
Vorherrschende Sprache
JavaScript
Sterne
479
Forks
738
Ø Merge
5 T. 1 Std.
Gemergte PRs (30 T.)
2

Entwicklungsumgebung

Erste Schritte

  1. Lesen Sie das ganze Issue und danach den Beitragsleitfaden des Projekts.
  2. Schreiben Sie ins Issue, dass Sie es übernehmen — das erspart doppelte Arbeit.
  3. Forken Sie das Repository und arbeiten Sie in einem Branch.
  4. Öffnen Sie einen Pull Request, der die Issue-Nummer nennt.

Mehr aus testing-library/testing-library-docs

Alle Issues in testing-library/testing-library-docs

Ähnliche Issues

Weitere Issues zu JavaScript

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.