From 057608376b6520f4081f2b5ed70e547446f91ae6 Mon Sep 17 00:00:00 2001 From: Thisen Date: Tue, 22 Sep 2020 22:12:07 +0200 Subject: [PATCH] fix configureCypressTestingLibrary typings --- types/index.d.ts | 396 ++++++++++++++++++++++++++--------------------- types/test.ts | 7 +- 2 files changed, 222 insertions(+), 181 deletions(-) diff --git a/types/index.d.ts b/types/index.d.ts index 77949bf..0f90b01 100644 --- a/types/index.d.ts +++ b/types/index.d.ts @@ -15,188 +15,226 @@ export interface CTLMatcherOptions { export type MatcherOptions = DTLMatcherOptions | CTLMatcherOptions export type ByRoleOptions = DTLByRoleOptions | CTLMatcherOptions -export type SelectorMatcherOptions = DTLSelectorMatcherOptions | CTLMatcherOptions +export type SelectorMatcherOptions = + | DTLSelectorMatcherOptions + | CTLMatcherOptions declare global { namespace Cypress { - interface Chainable { - /** - * dom-testing-library helpers for Cypress - * - * `findBy*` APIs search for an element and throw an error if nothing found - * `findAllBy*` APIs search for all elements and an error if nothing found - * - * @see https://github.com/testing-library/cypress-testing-library#usage - * @see https://github.com/testing-library/dom-testing-library#table-of-contents - */ - findByPlaceholderText(id: Matcher, options?: MatcherOptions): Chainable - - /** - * dom-testing-library helpers for Cypress - * - * `findBy*` APIs search for an element and throw an error if nothing found - * `findAllBy*` APIs search for all elements and an error if nothing found - * - * @see https://github.com/testing-library/cypress-testing-library#usage - * @see https://github.com/testing-library/dom-testing-library#table-of-contents - */ - findAllByPlaceholderText(id: Matcher, options?: MatcherOptions): Chainable - - /** - * dom-testing-library helpers for Cypress - * - * `findBy*` APIs search for an element and throw an error if nothing found - * `findAllBy*` APIs search for all elements and an error if nothing found - * - * @see https://github.com/testing-library/cypress-testing-library#usage - * @see https://github.com/testing-library/dom-testing-library#table-of-contents - */ - findByText(id: Matcher, options?: SelectorMatcherOptions): Chainable - - /** - * dom-testing-library helpers for Cypress - * - * `findBy*` APIs search for an element and throw an error if nothing found - * `findAllBy*` APIs search for all elements and an error if nothing found - * - * @see https://github.com/testing-library/cypress-testing-library#usage - * @see https://github.com/testing-library/dom-testing-library#table-of-contents - */ - findAllByText(id: Matcher, options?: SelectorMatcherOptions): Chainable - - /** - * dom-testing-library helpers for Cypress - * - * `findBy*` APIs search for an element and throw an error if nothing found - * `findAllBy*` APIs search for all elements and an error if nothing found - * - * @see https://github.com/testing-library/cypress-testing-library#usage - * @see https://github.com/testing-library/dom-testing-library#table-of-contents - */ - findByLabelText(id: Matcher, options?: SelectorMatcherOptions): Chainable - - /** - * dom-testing-library helpers for Cypress - * - * `findBy*` APIs search for an element and throw an error if nothing found - * `findAllBy*` APIs search for all elements and an error if nothing found - * - * @see https://github.com/testing-library/cypress-testing-library#usage - * @see https://github.com/testing-library/dom-testing-library#table-of-contents - */ - findAllByLabelText(id: Matcher, options?: SelectorMatcherOptions): Chainable - - /** - * dom-testing-library helpers for Cypress - * - * `findBy*` APIs search for an element and throw an error if nothing found - * `findAllBy*` APIs search for all elements and an error if nothing found - * - * @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 - - /** - * dom-testing-library helpers for Cypress - * - * `findBy*` APIs search for an element and throw an error if nothing found - * `findAllBy*` APIs search for all elements and an error if nothing found - * - * @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 - - /** - * dom-testing-library helpers for Cypress - * - * `findBy*` APIs search for an element and throw an error if nothing found - * `findAllBy*` APIs search for all elements and an error if nothing found - * - * @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 - - /** - * dom-testing-library helpers for Cypress - * - * `findBy*` APIs search for an element and throw an error if nothing found - * `findAllBy*` APIs search for all elements and an error if nothing found - * - * @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 - - /** - * dom-testing-library helpers for Cypress - * - * `findBy*` APIs search for an element and throw an error if nothing found - * `findAllBy*` APIs search for all elements and an error if nothing found - * - * @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 - - /** - * dom-testing-library helpers for Cypress - * - * `findBy*` APIs search for an element and throw an error if nothing found - * `findAllBy*` APIs search for all elements and an error if nothing found - * - * @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 - - /** - * dom-testing-library helpers for Cypress - * - * `findBy*` APIs search for an element and throw an error if nothing found - * `findAllBy*` APIs search for all elements and an error if nothing found - * - * @see https://github.com/testing-library/cypress-testing-library#usage - * @see https://github.com/testing-library/dom-testing-library#table-of-contents - */ - findByDisplayValue(id: Matcher, options?: MatcherOptions): Chainable - - /** - * dom-testing-library helpers for Cypress - * - * `findBy*` APIs search for an element and throw an error if nothing found - * `findAllBy*` APIs search for all elements and an error if nothing found - * - * @see https://github.com/testing-library/cypress-testing-library#usage - * @see https://github.com/testing-library/dom-testing-library#table-of-contents - */ - findAllByDisplayValue(id: Matcher, options?: MatcherOptions): Chainable - - /** - * dom-testing-library helpers for Cypress - * - * `findBy*` APIs search for an element and throw an error if nothing found - * `findAllBy*` APIs search for all elements and an error if nothing found - * - * @see https://github.com/testing-library/cypress-testing-library#usage - * @see https://github.com/testing-library/dom-testing-library#table-of-contents - */ - findByRole(id: Matcher, options?: ByRoleOptions): Chainable - - /** - * dom-testing-library helpers for Cypress - * - * `findBy*` APIs search for an element and throw an error if nothing found - * `findAllBy*` APIs search for all elements and an error if nothing found - * - * @see https://github.com/testing-library/cypress-testing-library#usage - * @see https://github.com/testing-library/dom-testing-library#table-of-contents - */ - findAllByRole(id: Matcher, options?: ByRoleOptions): Chainable - } + interface Chainable { + /** + * dom-testing-library helpers for Cypress + * + * `findBy*` APIs search for an element and throw an error if nothing found + * `findAllBy*` APIs search for all elements and an error if nothing found + * + * @see https://github.com/testing-library/cypress-testing-library#usage + * @see https://github.com/testing-library/dom-testing-library#table-of-contents + */ + findByPlaceholderText( + id: Matcher, + options?: MatcherOptions, + ): Chainable + + /** + * dom-testing-library helpers for Cypress + * + * `findBy*` APIs search for an element and throw an error if nothing found + * `findAllBy*` APIs search for all elements and an error if nothing found + * + * @see https://github.com/testing-library/cypress-testing-library#usage + * @see https://github.com/testing-library/dom-testing-library#table-of-contents + */ + findAllByPlaceholderText( + id: Matcher, + options?: MatcherOptions, + ): Chainable + + /** + * dom-testing-library helpers for Cypress + * + * `findBy*` APIs search for an element and throw an error if nothing found + * `findAllBy*` APIs search for all elements and an error if nothing found + * + * @see https://github.com/testing-library/cypress-testing-library#usage + * @see https://github.com/testing-library/dom-testing-library#table-of-contents + */ + findByText( + id: Matcher, + options?: SelectorMatcherOptions, + ): Chainable + + /** + * dom-testing-library helpers for Cypress + * + * `findBy*` APIs search for an element and throw an error if nothing found + * `findAllBy*` APIs search for all elements and an error if nothing found + * + * @see https://github.com/testing-library/cypress-testing-library#usage + * @see https://github.com/testing-library/dom-testing-library#table-of-contents + */ + findAllByText( + id: Matcher, + options?: SelectorMatcherOptions, + ): Chainable + + /** + * dom-testing-library helpers for Cypress + * + * `findBy*` APIs search for an element and throw an error if nothing found + * `findAllBy*` APIs search for all elements and an error if nothing found + * + * @see https://github.com/testing-library/cypress-testing-library#usage + * @see https://github.com/testing-library/dom-testing-library#table-of-contents + */ + findByLabelText( + id: Matcher, + options?: SelectorMatcherOptions, + ): Chainable + + /** + * dom-testing-library helpers for Cypress + * + * `findBy*` APIs search for an element and throw an error if nothing found + * `findAllBy*` APIs search for all elements and an error if nothing found + * + * @see https://github.com/testing-library/cypress-testing-library#usage + * @see https://github.com/testing-library/dom-testing-library#table-of-contents + */ + findAllByLabelText( + id: Matcher, + options?: SelectorMatcherOptions, + ): Chainable + + /** + * dom-testing-library helpers for Cypress + * + * `findBy*` APIs search for an element and throw an error if nothing found + * `findAllBy*` APIs search for all elements and an error if nothing found + * + * @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 + + /** + * dom-testing-library helpers for Cypress + * + * `findBy*` APIs search for an element and throw an error if nothing found + * `findAllBy*` APIs search for all elements and an error if nothing found + * + * @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 + + /** + * dom-testing-library helpers for Cypress + * + * `findBy*` APIs search for an element and throw an error if nothing found + * `findAllBy*` APIs search for all elements and an error if nothing found + * + * @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 + + /** + * dom-testing-library helpers for Cypress + * + * `findBy*` APIs search for an element and throw an error if nothing found + * `findAllBy*` APIs search for all elements and an error if nothing found + * + * @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 + + /** + * dom-testing-library helpers for Cypress + * + * `findBy*` APIs search for an element and throw an error if nothing found + * `findAllBy*` APIs search for all elements and an error if nothing found + * + * @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 + + /** + * dom-testing-library helpers for Cypress + * + * `findBy*` APIs search for an element and throw an error if nothing found + * `findAllBy*` APIs search for all elements and an error if nothing found + * + * @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 + + /** + * dom-testing-library helpers for Cypress + * + * `findBy*` APIs search for an element and throw an error if nothing found + * `findAllBy*` APIs search for all elements and an error if nothing found + * + * @see https://github.com/testing-library/cypress-testing-library#usage + * @see https://github.com/testing-library/dom-testing-library#table-of-contents + */ + findByDisplayValue( + id: Matcher, + options?: MatcherOptions, + ): Chainable + + /** + * dom-testing-library helpers for Cypress + * + * `findBy*` APIs search for an element and throw an error if nothing found + * `findAllBy*` APIs search for all elements and an error if nothing found + * + * @see https://github.com/testing-library/cypress-testing-library#usage + * @see https://github.com/testing-library/dom-testing-library#table-of-contents + */ + findAllByDisplayValue( + id: Matcher, + options?: MatcherOptions, + ): Chainable + + /** + * dom-testing-library helpers for Cypress + * + * `findBy*` APIs search for an element and throw an error if nothing found + * `findAllBy*` APIs search for all elements and an error if nothing found + * + * @see https://github.com/testing-library/cypress-testing-library#usage + * @see https://github.com/testing-library/dom-testing-library#table-of-contents + */ + findByRole(id: Matcher, options?: ByRoleOptions): Chainable + + /** + * dom-testing-library helpers for Cypress + * + * `findBy*` APIs search for an element and throw an error if nothing found + * `findAllBy*` APIs search for all elements and an error if nothing found + * + * @see https://github.com/testing-library/cypress-testing-library#usage + * @see https://github.com/testing-library/dom-testing-library#table-of-contents + */ + findAllByRole(id: Matcher, options?: ByRoleOptions): Chainable + + /** + * dom-testing-library helpers for Cypress + * + * Configure dom-testing-library through Cypress object. Wraps `configure(config)` + * + * @see https://github.com/testing-library/cypress-testing-library#usage + * @see https://github.com/testing-library/dom-testing-library#table-of-contents + */ + configureCypressTestingLibrary( + config: Parameters[0], + ): Chainable + } } } -export { configure } +export {configure} diff --git a/types/test.ts b/types/test.ts index bcf5e16..28f3bf9 100644 --- a/types/test.ts +++ b/types/test.ts @@ -1,8 +1,8 @@ /// -import { configure } from '@testing-library/cypress' +import {configure} from '@testing-library/cypress' import '@testing-library/cypress/add-commands' -configure({ testIdAttribute: 'data-myown-testid' }) +configure({testIdAttribute: 'data-myown-testid'}) // findBy* cy.findByPlaceholderText('foo') // $ExpectType Chainable> @@ -23,3 +23,6 @@ cy.findAllByTestId('foo') // $ExpectType Chainable> cy.findAllByTitle('foo') // $ExpectType Chainable> cy.findAllByDisplayValue('foo') // $ExpectType Chainable> cy.findAllByRole('foo') // $ExpectType Chainable> + +// configure +cy.configureCypressTestingLibrary({testIdAttribute: 'data-myawesome-testid'}) // $ExpectType Chainable