-
Notifications
You must be signed in to change notification settings - Fork 154
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(TS): move types from DefinitelyTyped (#148)
Co-authored-by: Kent C. Dodds <me+github@kentcdodds.com>
- Loading branch information
1 parent
ae925b4
commit fdaa7e5
Showing
7 changed files
with
278 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
// Allow `import '@testing-library/cypress/add-commands'` from a `cypress/commands.ts` file | ||
import './' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,202 @@ | ||
// TypeScript Version: 3.8 | ||
|
||
import { | ||
configure, | ||
Matcher, | ||
MatcherOptions as DTLMatcherOptions, | ||
ByRoleOptions as DTLByRoleOptions, | ||
SelectorMatcherOptions as DTLSelectorMatcherOptions, | ||
} from '@testing-library/dom' | ||
|
||
export interface CTLMatcherOptions { | ||
timeout?: number | ||
container?: HTMLElement | JQuery | ||
} | ||
|
||
export type MatcherOptions = DTLMatcherOptions | CTLMatcherOptions | ||
export type ByRoleOptions = DTLByRoleOptions | CTLMatcherOptions | ||
export type SelectorMatcherOptions = DTLSelectorMatcherOptions | CTLMatcherOptions | ||
|
||
declare global { | ||
namespace Cypress { | ||
interface Chainable<Subject = any> { | ||
/** | ||
* 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<JQuery> | ||
|
||
/** | ||
* 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<JQuery> | ||
|
||
/** | ||
* 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<JQuery> | ||
|
||
/** | ||
* 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<JQuery> | ||
|
||
/** | ||
* 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<JQuery> | ||
|
||
/** | ||
* 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<JQuery> | ||
|
||
/** | ||
* 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<JQuery> | ||
|
||
/** | ||
* 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<JQuery> | ||
|
||
/** | ||
* 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<JQuery> | ||
|
||
/** | ||
* 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<JQuery> | ||
|
||
/** | ||
* 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<JQuery> | ||
|
||
/** | ||
* 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<JQuery> | ||
|
||
/** | ||
* 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<JQuery> | ||
|
||
/** | ||
* 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<JQuery> | ||
|
||
/** | ||
* 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<JQuery> | ||
|
||
/** | ||
* 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<JQuery> | ||
} | ||
} | ||
} | ||
|
||
export { configure } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
/// <reference types="Cypress" /> | ||
import { configure } from '@testing-library/cypress' | ||
import '@testing-library/cypress/add-commands' | ||
|
||
configure({ testIdAttribute: 'data-myown-testid' }) | ||
|
||
// findBy* | ||
cy.findByPlaceholderText('foo') // $ExpectType Chainable<JQuery<HTMLElement>> | ||
cy.findByText('foo') // $ExpectType Chainable<JQuery<HTMLElement>> | ||
cy.findByLabelText('foo') // $ExpectType Chainable<JQuery<HTMLElement>> | ||
cy.findByAltText('foo') // $ExpectType Chainable<JQuery<HTMLElement>> | ||
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>> | ||
|
||
// findAllBy* | ||
cy.findAllByPlaceholderText('foo') // $ExpectType Chainable<JQuery<HTMLElement>> | ||
cy.findAllByText('foo') // $ExpectType Chainable<JQuery<HTMLElement>> | ||
cy.findAllByLabelText('foo') // $ExpectType Chainable<JQuery<HTMLElement>> | ||
cy.findAllByAltText('foo') // $ExpectType Chainable<JQuery<HTMLElement>> | ||
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>> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
{ | ||
"compilerOptions": { | ||
"module": "commonjs", | ||
"lib": ["es6", "dom"], | ||
"noImplicitAny": true, | ||
"noImplicitThis": true, | ||
"strictFunctionTypes": true, | ||
"strictNullChecks": true, | ||
"baseUrl": ".", | ||
"noEmit": true, | ||
"types": [], | ||
"paths": { | ||
"@testing-library/cypress": ["."] | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
{ | ||
"extends": ["dtslint/dtslint.json"], | ||
"rules": { | ||
"no-useless-files": false, | ||
"no-relative-import-in-test": false, | ||
"semicolon": false, | ||
"whitespace": false | ||
} | ||
} |