Skip to content

Add ability for users to supply generic type #258

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
71 changes: 46 additions & 25 deletions types/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,10 @@ declare global {
* @see https://github.com/testing-library/cypress-testing-library#usage
* @see https://github.com/testing-library/dom-testing-library#table-of-contents
*/
findByPlaceholderText(
findByPlaceholderText<E extends Node = HTMLElement>(
id: Matcher,
options?: MatcherOptions,
): Chainable<JQuery>
): Chainable<JQuery<E>>

/**
* dom-testing-library helpers for Cypress
Expand All @@ -49,10 +49,10 @@ declare global {
* @see https://github.com/testing-library/cypress-testing-library#usage
* @see https://github.com/testing-library/dom-testing-library#table-of-contents
*/
findAllByPlaceholderText(
findAllByPlaceholderText<E extends Node = HTMLElement>(
id: Matcher,
options?: MatcherOptions,
): Chainable<JQuery>
): Chainable<JQuery<E>>

/**
* dom-testing-library helpers for Cypress
Expand All @@ -63,10 +63,10 @@ declare global {
* @see https://github.com/testing-library/cypress-testing-library#usage
* @see https://github.com/testing-library/dom-testing-library#table-of-contents
*/
findByText(
findByText<E extends Node = HTMLElement>(
id: Matcher,
options?: SelectorMatcherOptions,
): Chainable<JQuery>
): Chainable<JQuery<E>>

/**
* dom-testing-library helpers for Cypress
Expand All @@ -77,10 +77,10 @@ declare global {
* @see https://github.com/testing-library/cypress-testing-library#usage
* @see https://github.com/testing-library/dom-testing-library#table-of-contents
*/
findAllByText(
findAllByText<E extends Node = HTMLElement>(
id: Matcher,
options?: SelectorMatcherOptions,
): Chainable<JQuery>
): Chainable<JQuery<E>>

/**
* dom-testing-library helpers for Cypress
Expand All @@ -91,10 +91,10 @@ declare global {
* @see https://github.com/testing-library/cypress-testing-library#usage
* @see https://github.com/testing-library/dom-testing-library#table-of-contents
*/
findByLabelText(
findByLabelText<E extends Node = HTMLElement>(
id: Matcher,
options?: SelectorMatcherOptions,
): Chainable<JQuery>
): Chainable<JQuery<E>>

/**
* dom-testing-library helpers for Cypress
Expand All @@ -105,10 +105,10 @@ declare global {
* @see https://github.com/testing-library/cypress-testing-library#usage
* @see https://github.com/testing-library/dom-testing-library#table-of-contents
*/
findAllByLabelText(
findAllByLabelText<E extends Node = HTMLElement>(
id: Matcher,
options?: SelectorMatcherOptions,
): Chainable<JQuery>
): Chainable<JQuery<E>>

/**
* dom-testing-library helpers for Cypress
Expand All @@ -119,7 +119,10 @@ declare global {
* @see https://github.com/testing-library/cypress-testing-library#usage
* @see https://github.com/testing-library/dom-testing-library#table-of-contents
*/
findByAltText(id: Matcher, options?: MatcherOptions): Chainable<JQuery>
findByAltText<E extends Node = HTMLElement>(
id: Matcher,
options?: MatcherOptions,
): Chainable<JQuery<E>>

/**
* dom-testing-library helpers for Cypress
Expand All @@ -130,7 +133,10 @@ declare global {
* @see https://github.com/testing-library/cypress-testing-library#usage
* @see https://github.com/testing-library/dom-testing-library#table-of-contents
*/
findAllByAltText(id: Matcher, options?: MatcherOptions): Chainable<JQuery>
findAllByAltText<E extends Node = HTMLElement>(
id: Matcher,
options?: MatcherOptions,
): Chainable<JQuery<E>>

/**
* dom-testing-library helpers for Cypress
Expand All @@ -141,7 +147,10 @@ declare global {
* @see https://github.com/testing-library/cypress-testing-library#usage
* @see https://github.com/testing-library/dom-testing-library#table-of-contents
*/
findByTestId(id: Matcher, options?: MatcherOptions): Chainable<JQuery>
findByTestId<E extends Node = HTMLElement>(
id: Matcher,
options?: MatcherOptions,
): Chainable<JQuery<E>>

/**
* dom-testing-library helpers for Cypress
Expand All @@ -152,7 +161,10 @@ declare global {
* @see https://github.com/testing-library/cypress-testing-library#usage
* @see https://github.com/testing-library/dom-testing-library#table-of-contents
*/
findAllByTestId(id: Matcher, options?: MatcherOptions): Chainable<JQuery>
findAllByTestId<E extends Node = HTMLElement>(
id: Matcher,
options?: MatcherOptions,
): Chainable<JQuery<E>>

/**
* dom-testing-library helpers for Cypress
Expand All @@ -163,7 +175,10 @@ declare global {
* @see https://github.com/testing-library/cypress-testing-library#usage
* @see https://github.com/testing-library/dom-testing-library#table-of-contents
*/
findByTitle(id: Matcher, options?: MatcherOptions): Chainable<JQuery>
findByTitle<E extends Node = HTMLElement>(
id: Matcher,
options?: MatcherOptions,
): Chainable<JQuery<E>>

/**
* dom-testing-library helpers for Cypress
Expand All @@ -174,7 +189,10 @@ declare global {
* @see https://github.com/testing-library/cypress-testing-library#usage
* @see https://github.com/testing-library/dom-testing-library#table-of-contents
*/
findAllByTitle(id: Matcher, options?: MatcherOptions): Chainable<JQuery>
findAllByTitle<E extends Node = HTMLElement>(
id: Matcher,
options?: MatcherOptions,
): Chainable<JQuery<E>>

/**
* dom-testing-library helpers for Cypress
Expand All @@ -185,10 +203,10 @@ declare global {
* @see https://github.com/testing-library/cypress-testing-library#usage
* @see https://github.com/testing-library/dom-testing-library#table-of-contents
*/
findByDisplayValue(
findByDisplayValue<E extends Node = HTMLElement>(
id: Matcher,
options?: MatcherOptions,
): Chainable<JQuery>
): Chainable<JQuery<E>>

/**
* dom-testing-library helpers for Cypress
Expand All @@ -199,10 +217,10 @@ declare global {
* @see https://github.com/testing-library/cypress-testing-library#usage
* @see https://github.com/testing-library/dom-testing-library#table-of-contents
*/
findAllByDisplayValue(
findAllByDisplayValue<E extends Node = HTMLElement>(
id: Matcher,
options?: MatcherOptions,
): Chainable<JQuery>
): Chainable<JQuery<E>>

/**
* dom-testing-library helpers for Cypress
Expand All @@ -213,7 +231,10 @@ declare global {
* @see https://github.com/testing-library/cypress-testing-library#usage
* @see https://github.com/testing-library/dom-testing-library#table-of-contents
*/
findByRole(id: ByRoleMatcher, options?: ByRoleOptions): Chainable<JQuery>
findByRole<E extends Node = HTMLElement>(
id: ByRoleMatcher,
options?: ByRoleOptions,
): Chainable<JQuery<E>>

/**
* dom-testing-library helpers for Cypress
Expand All @@ -224,10 +245,10 @@ declare global {
* @see https://github.com/testing-library/cypress-testing-library#usage
* @see https://github.com/testing-library/dom-testing-library#table-of-contents
*/
findAllByRole(
findAllByRole<E extends Node = HTMLElement>(
id: ByRoleMatcher,
options?: ByRoleOptions,
): Chainable<JQuery>
): Chainable<JQuery<E>>

/**
* dom-testing-library helpers for Cypress
Expand Down
8 changes: 7 additions & 1 deletion types/test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/// <reference types="Cypress" />
import {configure} from '.'
import './add-commands'
import './add-commands'

configure({testIdAttribute: 'data-myown-testid'})

Expand All @@ -13,6 +13,9 @@ cy.findByTestId('foo') // $ExpectType Chainable<JQuery<HTMLElement>>
cy.findByTitle('foo') // $ExpectType Chainable<JQuery<HTMLElement>>
cy.findByDisplayValue('foo') // $ExpectType Chainable<JQuery<HTMLElement>>
cy.findByRole('foo') // $ExpectType Chainable<JQuery<HTMLElement>>
// with types
cy.findByLabelText<HTMLInputElement>('foo') // $ExpectType Chainable<JQuery<HTMLInputElement>>
cy.findByRole<HTMLLinkElement>('link') // $ExpectType Chainable<JQuery<HTMLLinkElement>>

// findAllBy*
cy.findAllByPlaceholderText('foo') // $ExpectType Chainable<JQuery<HTMLElement>>
Expand All @@ -23,6 +26,9 @@ cy.findAllByTestId('foo') // $ExpectType Chainable<JQuery<HTMLElement>>
cy.findAllByTitle('foo') // $ExpectType Chainable<JQuery<HTMLElement>>
cy.findAllByDisplayValue('foo') // $ExpectType Chainable<JQuery<HTMLElement>>
cy.findAllByRole('foo') // $ExpectType Chainable<JQuery<HTMLElement>>
// with types
cy.findAllByLabelText<HTMLInputElement>('foo') // $ExpectType Chainable<JQuery<HTMLInputElement>>
cy.findAllByRole<HTMLLinkElement>('link') // $ExpectType Chainable<JQuery<HTMLLinkElement>>

// configure
cy.configureCypressTestingLibrary({testIdAttribute: 'data-myawesome-testid'}) // $ExpectType Chainable<void>
12 changes: 11 additions & 1 deletion types/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,14 @@
{
"extends": "../node_modules/kcd-scripts/shared-tsconfig.json",
"include": ["."]
"include": ["."],
"compilerOptions": {
"lib": ["ESNext", "DOM"],
"noImplicitAny": true,
"noImplicitThis": true,
"strictFunctionTypes": true,
"strictNullChecks": true,
"types": [],
"noEmit": true,
"forceConsistentCasingInFileNames": true
}
}