From f439ea144ddba6c2d4af0ba557a778b8dee2066c Mon Sep 17 00:00:00 2001 From: TheGallery <3214876+TheGallery@users.noreply.github.com> Date: Sat, 1 Aug 2020 14:01:52 +0100 Subject: [PATCH 1/6] Move type declarations from DefinitelyTyped --- package.json | 9 +- types/add-commands.d.ts | 2 + types/index.d.ts | 442 ++++++++++++++++++++++++++++++++++++++++ types/test.ts | 52 +++++ types/tsconfig.json | 16 ++ types/tslint.json | 9 + 6 files changed, 527 insertions(+), 3 deletions(-) create mode 100644 types/add-commands.d.ts create mode 100644 types/index.d.ts create mode 100644 types/test.ts create mode 100644 types/tsconfig.json create mode 100644 types/tslint.json diff --git a/package.json b/package.json index 036d9d1..e5a391c 100644 --- a/package.json +++ b/package.json @@ -3,6 +3,7 @@ "version": "0.0.0-semantically-released", "description": "Simple and complete custom Cypress commands and utilities that encourage good testing practices.", "main": "dist/index.js", + "types": "types/index.d.ts", "engines": { "node": ">=10", "npm": ">=6" @@ -18,11 +19,13 @@ "test:cypress:run": "cypress run", "test:unit": "kcd-scripts test --no-watch", "test:unit:watch": "kcd-scripts test", + "typecheck": "dtslint ./types/", "validate": "kcd-scripts validate build,lint,test" }, "files": [ "dist", - "add-commands.js" + "add-commands.js", + "types" ], "keywords": [ "testing", @@ -38,11 +41,11 @@ "license": "MIT", "dependencies": { "@babel/runtime": "^7.9.2", - "@testing-library/dom": "^7.1.0", - "@types/testing-library__cypress": "^5.0.3" + "@testing-library/dom": "^7.1.0" }, "devDependencies": { "cypress": "^4.2.0", + "dtslint": "^3.6.14", "kcd-scripts": "^5.5.0", "npm-run-all": "^4.1.5" }, diff --git a/types/add-commands.d.ts b/types/add-commands.d.ts new file mode 100644 index 0000000..e2ecc62 --- /dev/null +++ b/types/add-commands.d.ts @@ -0,0 +1,2 @@ +// Allow `import '@testing-library/cypress/add-commands'` from a `cypress/commands.ts` file +import './'; diff --git a/types/index.d.ts b/types/index.d.ts new file mode 100644 index 0000000..980a312 --- /dev/null +++ b/types/index.d.ts @@ -0,0 +1,442 @@ +// 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 { + /** + * 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 + * `queryBy*` APIs search for an element and returns null if nothing found + * `queryAllBy*` APIs search for all elements and return empty array 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 + */ + queryByPlaceholderText(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 + * `queryBy*` APIs search for an element and returns null if nothing found + * `queryAllBy*` APIs search for all elements and return empty array 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 + */ + queryAllByPlaceholderText(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 + * `queryBy*` APIs search for an element and returns null if nothing found + * `queryAllBy*` APIs search for all elements and return empty array 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 + * `queryBy*` APIs search for an element and returns null if nothing found + * `queryAllBy*` APIs search for all elements and return empty array 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 + * `queryBy*` APIs search for an element and returns null if nothing found + * `queryAllBy*` APIs search for all elements and return empty array 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 + */ + queryByText(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 + * `queryBy*` APIs search for an element and returns null if nothing found + * `queryAllBy*` APIs search for all elements and return empty array 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 + */ + queryAllByText(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 + * `queryBy*` APIs search for an element and returns null if nothing found + * `queryAllBy*` APIs search for all elements and return empty array 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 + * `queryBy*` APIs search for an element and returns null if nothing found + * `queryAllBy*` APIs search for all elements and return empty array 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 + * `queryBy*` APIs search for an element and returns null if nothing found + * `queryAllBy*` APIs search for all elements and return empty array 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 + */ + queryByLabelText(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 + * `queryBy*` APIs search for an element and returns null if nothing found + * `queryAllBy*` APIs search for all elements and return empty array 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 + */ + queryAllByLabelText(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 + * `queryBy*` APIs search for an element and returns null if nothing found + * `queryAllBy*` APIs search for all elements and return empty array 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 + * `queryBy*` APIs search for an element and returns null if nothing found + * `queryAllBy*` APIs search for all elements and return empty array 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 + * `queryBy*` APIs search for an element and returns null if nothing found + * `queryAllBy*` APIs search for all elements and return empty array 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 + */ + queryByAltText(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 + * `queryBy*` APIs search for an element and returns null if nothing found + * `queryAllBy*` APIs search for all elements and return empty array 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 + */ + queryAllByAltText(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 + * `queryBy*` APIs search for an element and returns null if nothing found + * `queryAllBy*` APIs search for all elements and return empty array 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 + * `queryBy*` APIs search for an element and returns null if nothing found + * `queryAllBy*` APIs search for all elements and return empty array 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 + * `queryBy*` APIs search for an element and returns null if nothing found + * `queryAllBy*` APIs search for all elements and return empty array 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 + */ + queryByTestId(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 + * `queryBy*` APIs search for an element and returns null if nothing found + * `queryAllBy*` APIs search for all elements and return empty array 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 + */ + queryAllByTestId(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 + * `queryBy*` APIs search for an element and returns null if nothing found + * `queryAllBy*` APIs search for all elements and return empty array 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 + * `queryBy*` APIs search for an element and returns null if nothing found + * `queryAllBy*` APIs search for all elements and return empty array 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 + * `queryBy*` APIs search for an element and returns null if nothing found + * `queryAllBy*` APIs search for all elements and return empty array 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 + */ + queryByTitle(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 + * `queryBy*` APIs search for an element and returns null if nothing found + * `queryAllBy*` APIs search for all elements and return empty array 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 + */ + queryAllByTitle(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 + * `queryBy*` APIs search for an element and returns null if nothing found + * `queryAllBy*` APIs search for all elements and return empty array 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 + * `queryBy*` APIs search for an element and returns null if nothing found + * `queryAllBy*` APIs search for all elements and return empty array 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 + * `queryBy*` APIs search for an element and returns null if nothing found + * `queryAllBy*` APIs search for all elements and return empty array 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 + */ + queryByDisplayValue(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 + * `queryBy*` APIs search for an element and returns null if nothing found + * `queryAllBy*` APIs search for all elements and return empty array 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 + */ + queryAllByDisplayValue(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 + * `queryBy*` APIs search for an element and returns null if nothing found + * `queryAllBy*` APIs search for all elements and return empty array 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 + * `queryBy*` APIs search for an element and returns null if nothing found + * `queryAllBy*` APIs search for all elements and return empty array 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 + * `queryBy*` APIs search for an element and returns null if nothing found + * `queryAllBy*` APIs search for all elements and return empty array 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 + */ + queryByRole(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 + * `queryBy*` APIs search for an element and returns null if nothing found + * `queryAllBy*` APIs search for all elements and return empty array 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 + */ + queryAllByRole(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 + * `queryBy*` APIs search for an element and returns null if nothing found + * `queryAllBy*` APIs search for all elements and return empty array 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 + * `queryBy*` APIs search for an element and returns null if nothing found + * `queryAllBy*` APIs search for all elements and return empty array 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; + } + } +} + +export { configure }; diff --git a/types/test.ts b/types/test.ts new file mode 100644 index 0000000..557d91d --- /dev/null +++ b/types/test.ts @@ -0,0 +1,52 @@ +/// +import { configure } from '@testing-library/cypress'; +import '@testing-library/cypress/add-commands'; + +configure({ testIdAttribute: 'data-myown-testid' }); + +// findBy* +cy.findByPlaceholderText('foo'); // $ExpectType Chainable> +cy.findByText('foo'); // $ExpectType Chainable> +cy.findByLabelText('foo'); // $ExpectType Chainable> +cy.findByAltText('foo'); // $ExpectType Chainable> +cy.findByTestId('foo'); // $ExpectType Chainable> +cy.findByTitle('foo'); // $ExpectType Chainable> +cy.findByDisplayValue('foo'); // $ExpectType Chainable> +cy.findByRole('foo'); // $ExpectType Chainable> + +// findAllBy* +cy.findAllByPlaceholderText('foo'); // $ExpectType Chainable> +cy.findAllByText('foo'); // $ExpectType Chainable> +cy.findAllByLabelText('foo'); // $ExpectType Chainable> +cy.findAllByAltText('foo'); // $ExpectType Chainable> +cy.findAllByTestId('foo'); // $ExpectType Chainable> +cy.findAllByTitle('foo'); // $ExpectType Chainable> +cy.findAllByDisplayValue('foo'); // $ExpectType Chainable> +cy.findAllByRole('foo'); // $ExpectType Chainable> + +// queryBy* +cy.queryByPlaceholderText('foo'); // $ExpectType Chainable> +cy.queryByText('foo'); // $ExpectType Chainable> +cy.queryByLabelText('foo'); // $ExpectType Chainable> +cy.queryByAltText('foo'); // $ExpectType Chainable> +cy.queryByTestId('foo'); // $ExpectType Chainable> +cy.queryByTitle('foo'); // $ExpectType Chainable> +cy.queryByDisplayValue('foo'); // $ExpectType Chainable> +cy.queryByRole('foo'); // $ExpectType Chainable> + +// queryAllBy* +cy.queryAllByPlaceholderText('foo'); // $ExpectType Chainable> +cy.queryAllByText('foo'); // $ExpectType Chainable> +cy.queryAllByLabelText('foo'); // $ExpectType Chainable> +cy.queryAllByAltText('foo'); // $ExpectType Chainable> +cy.queryAllByTestId('foo'); // $ExpectType Chainable> +cy.queryAllByTitle('foo'); // $ExpectType Chainable> +cy.queryAllByDisplayValue('foo'); // $ExpectType Chainable> +cy.queryAllByRole('foo'); // $ExpectType Chainable> + +// with container option +const container = document.createElement('div'); +cy.queryAllByRole('foo', { container }); // $ExpectType Chainable> + +const $container = cy.$$('body').append('div'); +cy.queryAllByRole('foo', { container: $container }); // $ExpectType Chainable> diff --git a/types/tsconfig.json b/types/tsconfig.json new file mode 100644 index 0000000..22497e9 --- /dev/null +++ b/types/tsconfig.json @@ -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": ["."] + } + } +} diff --git a/types/tslint.json b/types/tslint.json new file mode 100644 index 0000000..cb0fce9 --- /dev/null +++ b/types/tslint.json @@ -0,0 +1,9 @@ +{ + "extends": ["dtslint/dtslint.json"], + "rules": { + "no-useless-files": false, + "no-relative-import-in-test": false, + "semicolon": false, + "whitespace": false + } +} From a893d303c928a092a1f58f3bbff7984d1015997a Mon Sep 17 00:00:00 2001 From: TheGallery <3214876+TheGallery@users.noreply.github.com> Date: Sun, 16 Aug 2020 14:58:02 +0100 Subject: [PATCH 2/6] Remove semicolons --- types/add-commands.d.ts | 2 +- types/index.d.ts | 78 ++++++++++++++++++++--------------------- types/test.ts | 78 ++++++++++++++++++++--------------------- 3 files changed, 79 insertions(+), 79 deletions(-) diff --git a/types/add-commands.d.ts b/types/add-commands.d.ts index e2ecc62..e6285e5 100644 --- a/types/add-commands.d.ts +++ b/types/add-commands.d.ts @@ -1,2 +1,2 @@ // Allow `import '@testing-library/cypress/add-commands'` from a `cypress/commands.ts` file -import './'; +import './' diff --git a/types/index.d.ts b/types/index.d.ts index 980a312..b48f0d1 100644 --- a/types/index.d.ts +++ b/types/index.d.ts @@ -6,16 +6,16 @@ import { MatcherOptions as DTLMatcherOptions, ByRoleOptions as DTLByRoleOptions, SelectorMatcherOptions as DTLSelectorMatcherOptions, -} from '@testing-library/dom'; +} from '@testing-library/dom' export interface CTLMatcherOptions { - timeout?: number; - container?: HTMLElement | JQuery; + timeout?: number + container?: HTMLElement | JQuery } -export type MatcherOptions = DTLMatcherOptions | CTLMatcherOptions; -export type ByRoleOptions = DTLByRoleOptions | CTLMatcherOptions; -export type SelectorMatcherOptions = DTLSelectorMatcherOptions | CTLMatcherOptions; +export type MatcherOptions = DTLMatcherOptions | CTLMatcherOptions +export type ByRoleOptions = DTLByRoleOptions | CTLMatcherOptions +export type SelectorMatcherOptions = DTLSelectorMatcherOptions | CTLMatcherOptions declare global { namespace Cypress { @@ -31,7 +31,7 @@ declare global { * @see https://github.com/testing-library/cypress-testing-library#usage * @see https://github.com/testing-library/dom-testing-library#table-of-contents */ - queryByPlaceholderText(id: Matcher, options?: MatcherOptions): Chainable; + queryByPlaceholderText(id: Matcher, options?: MatcherOptions): Chainable /** * dom-testing-library helpers for Cypress @@ -44,7 +44,7 @@ declare global { * @see https://github.com/testing-library/cypress-testing-library#usage * @see https://github.com/testing-library/dom-testing-library#table-of-contents */ - queryAllByPlaceholderText(id: Matcher, options?: MatcherOptions): Chainable; + queryAllByPlaceholderText(id: Matcher, options?: MatcherOptions): Chainable /** * dom-testing-library helpers for Cypress @@ -57,7 +57,7 @@ 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(id: Matcher, options?: MatcherOptions): Chainable; + findByPlaceholderText(id: Matcher, options?: MatcherOptions): Chainable /** * dom-testing-library helpers for Cypress @@ -70,7 +70,7 @@ 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(id: Matcher, options?: MatcherOptions): Chainable; + findAllByPlaceholderText(id: Matcher, options?: MatcherOptions): Chainable /** * dom-testing-library helpers for Cypress @@ -83,7 +83,7 @@ declare global { * @see https://github.com/testing-library/cypress-testing-library#usage * @see https://github.com/testing-library/dom-testing-library#table-of-contents */ - queryByText(id: Matcher, options?: SelectorMatcherOptions): Chainable; + queryByText(id: Matcher, options?: SelectorMatcherOptions): Chainable /** * dom-testing-library helpers for Cypress @@ -96,7 +96,7 @@ declare global { * @see https://github.com/testing-library/cypress-testing-library#usage * @see https://github.com/testing-library/dom-testing-library#table-of-contents */ - queryAllByText(id: Matcher, options?: SelectorMatcherOptions): Chainable; + queryAllByText(id: Matcher, options?: SelectorMatcherOptions): Chainable /** * dom-testing-library helpers for Cypress @@ -109,7 +109,7 @@ 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(id: Matcher, options?: SelectorMatcherOptions): Chainable; + findByText(id: Matcher, options?: SelectorMatcherOptions): Chainable /** * dom-testing-library helpers for Cypress @@ -122,7 +122,7 @@ 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(id: Matcher, options?: SelectorMatcherOptions): Chainable; + findAllByText(id: Matcher, options?: SelectorMatcherOptions): Chainable /** * dom-testing-library helpers for Cypress @@ -135,7 +135,7 @@ declare global { * @see https://github.com/testing-library/cypress-testing-library#usage * @see https://github.com/testing-library/dom-testing-library#table-of-contents */ - queryByLabelText(id: Matcher, options?: SelectorMatcherOptions): Chainable; + queryByLabelText(id: Matcher, options?: SelectorMatcherOptions): Chainable /** * dom-testing-library helpers for Cypress @@ -148,7 +148,7 @@ declare global { * @see https://github.com/testing-library/cypress-testing-library#usage * @see https://github.com/testing-library/dom-testing-library#table-of-contents */ - queryAllByLabelText(id: Matcher, options?: SelectorMatcherOptions): Chainable; + queryAllByLabelText(id: Matcher, options?: SelectorMatcherOptions): Chainable /** * dom-testing-library helpers for Cypress @@ -161,7 +161,7 @@ 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(id: Matcher, options?: SelectorMatcherOptions): Chainable; + findByLabelText(id: Matcher, options?: SelectorMatcherOptions): Chainable /** * dom-testing-library helpers for Cypress @@ -174,7 +174,7 @@ 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(id: Matcher, options?: SelectorMatcherOptions): Chainable; + findAllByLabelText(id: Matcher, options?: SelectorMatcherOptions): Chainable /** * dom-testing-library helpers for Cypress @@ -187,7 +187,7 @@ declare global { * @see https://github.com/testing-library/cypress-testing-library#usage * @see https://github.com/testing-library/dom-testing-library#table-of-contents */ - queryByAltText(id: Matcher, options?: MatcherOptions): Chainable; + queryByAltText(id: Matcher, options?: MatcherOptions): Chainable /** * dom-testing-library helpers for Cypress @@ -200,7 +200,7 @@ declare global { * @see https://github.com/testing-library/cypress-testing-library#usage * @see https://github.com/testing-library/dom-testing-library#table-of-contents */ - queryAllByAltText(id: Matcher, options?: MatcherOptions): Chainable; + queryAllByAltText(id: Matcher, options?: MatcherOptions): Chainable /** * dom-testing-library helpers for Cypress @@ -213,7 +213,7 @@ 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; + findByAltText(id: Matcher, options?: MatcherOptions): Chainable /** * dom-testing-library helpers for Cypress @@ -226,7 +226,7 @@ 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; + findAllByAltText(id: Matcher, options?: MatcherOptions): Chainable /** * dom-testing-library helpers for Cypress @@ -239,7 +239,7 @@ declare global { * @see https://github.com/testing-library/cypress-testing-library#usage * @see https://github.com/testing-library/dom-testing-library#table-of-contents */ - queryByTestId(id: Matcher, options?: MatcherOptions): Chainable; + queryByTestId(id: Matcher, options?: MatcherOptions): Chainable /** * dom-testing-library helpers for Cypress @@ -252,7 +252,7 @@ declare global { * @see https://github.com/testing-library/cypress-testing-library#usage * @see https://github.com/testing-library/dom-testing-library#table-of-contents */ - queryAllByTestId(id: Matcher, options?: MatcherOptions): Chainable; + queryAllByTestId(id: Matcher, options?: MatcherOptions): Chainable /** * dom-testing-library helpers for Cypress @@ -265,7 +265,7 @@ 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; + findByTestId(id: Matcher, options?: MatcherOptions): Chainable /** * dom-testing-library helpers for Cypress @@ -278,7 +278,7 @@ 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; + findAllByTestId(id: Matcher, options?: MatcherOptions): Chainable /** * dom-testing-library helpers for Cypress @@ -291,7 +291,7 @@ declare global { * @see https://github.com/testing-library/cypress-testing-library#usage * @see https://github.com/testing-library/dom-testing-library#table-of-contents */ - queryByTitle(id: Matcher, options?: MatcherOptions): Chainable; + queryByTitle(id: Matcher, options?: MatcherOptions): Chainable /** * dom-testing-library helpers for Cypress @@ -304,7 +304,7 @@ declare global { * @see https://github.com/testing-library/cypress-testing-library#usage * @see https://github.com/testing-library/dom-testing-library#table-of-contents */ - queryAllByTitle(id: Matcher, options?: MatcherOptions): Chainable; + queryAllByTitle(id: Matcher, options?: MatcherOptions): Chainable /** * dom-testing-library helpers for Cypress @@ -317,7 +317,7 @@ 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; + findByTitle(id: Matcher, options?: MatcherOptions): Chainable /** * dom-testing-library helpers for Cypress @@ -330,7 +330,7 @@ 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; + findAllByTitle(id: Matcher, options?: MatcherOptions): Chainable /** * dom-testing-library helpers for Cypress @@ -343,7 +343,7 @@ declare global { * @see https://github.com/testing-library/cypress-testing-library#usage * @see https://github.com/testing-library/dom-testing-library#table-of-contents */ - queryByDisplayValue(id: Matcher, options?: MatcherOptions): Chainable; + queryByDisplayValue(id: Matcher, options?: MatcherOptions): Chainable /** * dom-testing-library helpers for Cypress @@ -356,7 +356,7 @@ declare global { * @see https://github.com/testing-library/cypress-testing-library#usage * @see https://github.com/testing-library/dom-testing-library#table-of-contents */ - queryAllByDisplayValue(id: Matcher, options?: MatcherOptions): Chainable; + queryAllByDisplayValue(id: Matcher, options?: MatcherOptions): Chainable /** * dom-testing-library helpers for Cypress @@ -369,7 +369,7 @@ 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(id: Matcher, options?: MatcherOptions): Chainable; + findByDisplayValue(id: Matcher, options?: MatcherOptions): Chainable /** * dom-testing-library helpers for Cypress @@ -382,7 +382,7 @@ 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(id: Matcher, options?: MatcherOptions): Chainable; + findAllByDisplayValue(id: Matcher, options?: MatcherOptions): Chainable /** * dom-testing-library helpers for Cypress @@ -395,7 +395,7 @@ declare global { * @see https://github.com/testing-library/cypress-testing-library#usage * @see https://github.com/testing-library/dom-testing-library#table-of-contents */ - queryByRole(id: Matcher, options?: ByRoleOptions): Chainable; + queryByRole(id: Matcher, options?: ByRoleOptions): Chainable /** * dom-testing-library helpers for Cypress @@ -408,7 +408,7 @@ declare global { * @see https://github.com/testing-library/cypress-testing-library#usage * @see https://github.com/testing-library/dom-testing-library#table-of-contents */ - queryAllByRole(id: Matcher, options?: ByRoleOptions): Chainable; + queryAllByRole(id: Matcher, options?: ByRoleOptions): Chainable /** * dom-testing-library helpers for Cypress @@ -421,7 +421,7 @@ 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: Matcher, options?: ByRoleOptions): Chainable; + findByRole(id: Matcher, options?: ByRoleOptions): Chainable /** * dom-testing-library helpers for Cypress @@ -434,9 +434,9 @@ 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(id: Matcher, options?: ByRoleOptions): Chainable; + findAllByRole(id: Matcher, options?: ByRoleOptions): Chainable } } } -export { configure }; +export { configure } diff --git a/types/test.ts b/types/test.ts index 557d91d..4339e8d 100644 --- a/types/test.ts +++ b/types/test.ts @@ -1,52 +1,52 @@ /// -import { configure } from '@testing-library/cypress'; -import '@testing-library/cypress/add-commands'; +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> -cy.findByText('foo'); // $ExpectType Chainable> -cy.findByLabelText('foo'); // $ExpectType Chainable> -cy.findByAltText('foo'); // $ExpectType Chainable> -cy.findByTestId('foo'); // $ExpectType Chainable> -cy.findByTitle('foo'); // $ExpectType Chainable> -cy.findByDisplayValue('foo'); // $ExpectType Chainable> -cy.findByRole('foo'); // $ExpectType Chainable> +cy.findByPlaceholderText('foo') // $ExpectType Chainable> +cy.findByText('foo') // $ExpectType Chainable> +cy.findByLabelText('foo') // $ExpectType Chainable> +cy.findByAltText('foo') // $ExpectType Chainable> +cy.findByTestId('foo') // $ExpectType Chainable> +cy.findByTitle('foo') // $ExpectType Chainable> +cy.findByDisplayValue('foo') // $ExpectType Chainable> +cy.findByRole('foo') // $ExpectType Chainable> // findAllBy* -cy.findAllByPlaceholderText('foo'); // $ExpectType Chainable> -cy.findAllByText('foo'); // $ExpectType Chainable> -cy.findAllByLabelText('foo'); // $ExpectType Chainable> -cy.findAllByAltText('foo'); // $ExpectType Chainable> -cy.findAllByTestId('foo'); // $ExpectType Chainable> -cy.findAllByTitle('foo'); // $ExpectType Chainable> -cy.findAllByDisplayValue('foo'); // $ExpectType Chainable> -cy.findAllByRole('foo'); // $ExpectType Chainable> +cy.findAllByPlaceholderText('foo') // $ExpectType Chainable> +cy.findAllByText('foo') // $ExpectType Chainable> +cy.findAllByLabelText('foo') // $ExpectType Chainable> +cy.findAllByAltText('foo') // $ExpectType Chainable> +cy.findAllByTestId('foo') // $ExpectType Chainable> +cy.findAllByTitle('foo') // $ExpectType Chainable> +cy.findAllByDisplayValue('foo') // $ExpectType Chainable> +cy.findAllByRole('foo') // $ExpectType Chainable> // queryBy* -cy.queryByPlaceholderText('foo'); // $ExpectType Chainable> -cy.queryByText('foo'); // $ExpectType Chainable> -cy.queryByLabelText('foo'); // $ExpectType Chainable> -cy.queryByAltText('foo'); // $ExpectType Chainable> -cy.queryByTestId('foo'); // $ExpectType Chainable> -cy.queryByTitle('foo'); // $ExpectType Chainable> -cy.queryByDisplayValue('foo'); // $ExpectType Chainable> -cy.queryByRole('foo'); // $ExpectType Chainable> +cy.queryByPlaceholderText('foo') // $ExpectType Chainable> +cy.queryByText('foo') // $ExpectType Chainable> +cy.queryByLabelText('foo') // $ExpectType Chainable> +cy.queryByAltText('foo') // $ExpectType Chainable> +cy.queryByTestId('foo') // $ExpectType Chainable> +cy.queryByTitle('foo') // $ExpectType Chainable> +cy.queryByDisplayValue('foo') // $ExpectType Chainable> +cy.queryByRole('foo') // $ExpectType Chainable> // queryAllBy* -cy.queryAllByPlaceholderText('foo'); // $ExpectType Chainable> -cy.queryAllByText('foo'); // $ExpectType Chainable> -cy.queryAllByLabelText('foo'); // $ExpectType Chainable> -cy.queryAllByAltText('foo'); // $ExpectType Chainable> -cy.queryAllByTestId('foo'); // $ExpectType Chainable> -cy.queryAllByTitle('foo'); // $ExpectType Chainable> -cy.queryAllByDisplayValue('foo'); // $ExpectType Chainable> -cy.queryAllByRole('foo'); // $ExpectType Chainable> +cy.queryAllByPlaceholderText('foo') // $ExpectType Chainable> +cy.queryAllByText('foo') // $ExpectType Chainable> +cy.queryAllByLabelText('foo') // $ExpectType Chainable> +cy.queryAllByAltText('foo') // $ExpectType Chainable> +cy.queryAllByTestId('foo') // $ExpectType Chainable> +cy.queryAllByTitle('foo') // $ExpectType Chainable> +cy.queryAllByDisplayValue('foo') // $ExpectType Chainable> +cy.queryAllByRole('foo') // $ExpectType Chainable> // with container option -const container = document.createElement('div'); -cy.queryAllByRole('foo', { container }); // $ExpectType Chainable> +const container = document.createElement('div') +cy.queryAllByRole('foo', { container }) // $ExpectType Chainable> -const $container = cy.$$('body').append('div'); -cy.queryAllByRole('foo', { container: $container }); // $ExpectType Chainable> +const $container = cy.$$('body').append('div') +cy.queryAllByRole('foo', { container: $container }) // $ExpectType Chainable> From 06f81327b0fc310ca508b934495f4f9f802ee68b Mon Sep 17 00:00:00 2001 From: TheGallery <3214876+TheGallery@users.noreply.github.com> Date: Sun, 16 Aug 2020 15:00:08 +0100 Subject: [PATCH 3/6] Update README --- README.md | 29 +++++++++++++++++------------ 1 file changed, 17 insertions(+), 12 deletions(-) diff --git a/README.md b/README.md index a982ac6..674ffde 100644 --- a/README.md +++ b/README.md @@ -58,10 +58,13 @@ This allows you to use all the useful + - [Installation](#installation) - [With TypeScript](#with-typescript) + - [Intellisense for JavaScript with VS Code](#intellisense-for-javascript-with-vs-code) - [Usage](#usage) - [Differences from DOM Testing Library](#differences-from-dom-testing-library) +- [Config testIdAttribute](#config-testidattribute) - [Other Solutions](#other-solutions) - [Contributors](#contributors) - [LICENSE](#license) @@ -79,21 +82,21 @@ npm install --save-dev @testing-library/cypress ### With TypeScript -Typings are defined in `@types/testing-library__cypress` at -[DefinitelyTyped](https://github.com/DefinitelyTyped/DefinitelyTyped/tree/master/types/testing-library__cypress), -and should be added as follows in `tsconfig.json`: +Typings should be added as follows in `tsconfig.json`: ```json { "compilerOptions": { - "types": ["cypress", "@types/testing-library__cypress"] + "types": ["cypress", "@testing-library/cypress"] } } ``` ### Intellisense for JavaScript with VS Code -If you're not using TypeScript, you use VS Code, and want to have code-completion with the methods from this library, simply add the following line to your project's root-level `jsconfig.json` file: +If you're not using TypeScript, you use VS Code, and want to have +code-completion with the methods from this library, simply add the following +line to your project's root-level `jsconfig.json` file: ```json { @@ -116,7 +119,7 @@ commands. [See the `DOM Testing Library` docs for reference](https://testing-library.com) You can find -[all Library definitions here](https://github.com/DefinitelyTyped/DefinitelyTyped/tree/master/types/testing-library__cypress/index.d.ts). +[all Library definitions here](https://github.com/testing-library/cypress-testing-library/tree/master/types/index.d.ts). To configure DOM Testing Library, use the following custom command: @@ -134,9 +137,7 @@ cy.findAllByLabelText('Label text', {timeout: 7000}).should('exist') cy.findAllByText('Jackie Chan').click() // findAllByText _inside_ a form element -cy.get('form') - .findAllByText('Button Text') - .should('exist') +cy.get('form').findAllByText('Button Text').should('exist') ``` ### Differences from DOM Testing Library @@ -177,14 +178,16 @@ cy.findByText('Some Text').should('exist') ## Config testIdAttribute -If you would like to change the default testId from `data-testId` to `data-test-id`, add to your project's `cypress/support/index.js`: +If you would like to change the default testId from `data-testId` to +`data-test-id`, add to your project's `cypress/support/index.js`: ```javascript import {configure} from '@testing-library/cypress' configure({testIdAttribute: 'data-test-id'}) ``` -It accepts all configurations listed in [DOM testing library](https://testing-library.com/docs/dom-testing-library/api-configuration). +It accepts all configurations listed in +[DOM testing library](https://testing-library.com/docs/dom-testing-library/api-configuration). ## Other Solutions @@ -247,6 +250,7 @@ Thanks goes to these people ([emoji key][emojis]): + This project follows the [all-contributors][all-contributors] specification. @@ -297,5 +301,6 @@ MIT [all-contributors]: https://github.com/all-contributors/all-contributors [dom-testing-library]: https://github.com/testing-library/dom-testing-library [cypress]: https://www.cypress.io/ -[discord-badge]: https://img.shields.io/discord/723559267868737556.svg?color=7389D8&labelColor=6A7EC2&logo=discord&logoColor=ffffff&style=flat-square +[discord-badge]: + https://img.shields.io/discord/723559267868737556.svg?color=7389D8&labelColor=6A7EC2&logo=discord&logoColor=ffffff&style=flat-square [discord]: https://discord.gg/c6JN9fM From 25f26b065225816d91c7c85ffa40f89f21a60253 Mon Sep 17 00:00:00 2001 From: "Kent C. Dodds" Date: Sun, 16 Aug 2020 09:32:42 -0600 Subject: [PATCH 4/6] Update package.json --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index e5a391c..17fe556 100644 --- a/package.json +++ b/package.json @@ -20,7 +20,7 @@ "test:unit": "kcd-scripts test --no-watch", "test:unit:watch": "kcd-scripts test", "typecheck": "dtslint ./types/", - "validate": "kcd-scripts validate build,lint,test" + "validate": "kcd-scripts validate build,lint,test,typecheck" }, "files": [ "dist", From d91872ce96e1ad0d082f10443965f5f77c59b3cf Mon Sep 17 00:00:00 2001 From: Iosif Psychas <3214876+TheGallery@users.noreply.github.com> Date: Tue, 18 Aug 2020 21:27:48 +0100 Subject: [PATCH 5/6] Remove types for depracated queries --- types/index.d.ts | 240 ----------------------------------------------- types/test.ts | 27 ------ 2 files changed, 267 deletions(-) diff --git a/types/index.d.ts b/types/index.d.ts index b48f0d1..77949bf 100644 --- a/types/index.d.ts +++ b/types/index.d.ts @@ -25,34 +25,6 @@ declare global { * * `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 - * `queryBy*` APIs search for an element and returns null if nothing found - * `queryAllBy*` APIs search for all elements and return empty array 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 - */ - queryByPlaceholderText(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 - * `queryBy*` APIs search for an element and returns null if nothing found - * `queryAllBy*` APIs search for all elements and return empty array 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 - */ - queryAllByPlaceholderText(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 - * `queryBy*` APIs search for an element and returns null if nothing found - * `queryAllBy*` APIs search for all elements and return empty array 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 @@ -64,8 +36,6 @@ declare global { * * `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 - * `queryBy*` APIs search for an element and returns null if nothing found - * `queryAllBy*` APIs search for all elements and return empty array 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 @@ -77,34 +47,6 @@ declare global { * * `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 - * `queryBy*` APIs search for an element and returns null if nothing found - * `queryAllBy*` APIs search for all elements and return empty array 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 - */ - queryByText(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 - * `queryBy*` APIs search for an element and returns null if nothing found - * `queryAllBy*` APIs search for all elements and return empty array 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 - */ - queryAllByText(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 - * `queryBy*` APIs search for an element and returns null if nothing found - * `queryAllBy*` APIs search for all elements and return empty array 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 @@ -116,8 +58,6 @@ declare global { * * `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 - * `queryBy*` APIs search for an element and returns null if nothing found - * `queryAllBy*` APIs search for all elements and return empty array 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 @@ -129,34 +69,6 @@ declare global { * * `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 - * `queryBy*` APIs search for an element and returns null if nothing found - * `queryAllBy*` APIs search for all elements and return empty array 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 - */ - queryByLabelText(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 - * `queryBy*` APIs search for an element and returns null if nothing found - * `queryAllBy*` APIs search for all elements and return empty array 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 - */ - queryAllByLabelText(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 - * `queryBy*` APIs search for an element and returns null if nothing found - * `queryAllBy*` APIs search for all elements and return empty array 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 @@ -168,8 +80,6 @@ declare global { * * `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 - * `queryBy*` APIs search for an element and returns null if nothing found - * `queryAllBy*` APIs search for all elements and return empty array 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 @@ -181,34 +91,6 @@ declare global { * * `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 - * `queryBy*` APIs search for an element and returns null if nothing found - * `queryAllBy*` APIs search for all elements and return empty array 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 - */ - queryByAltText(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 - * `queryBy*` APIs search for an element and returns null if nothing found - * `queryAllBy*` APIs search for all elements and return empty array 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 - */ - queryAllByAltText(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 - * `queryBy*` APIs search for an element and returns null if nothing found - * `queryAllBy*` APIs search for all elements and return empty array 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 @@ -220,8 +102,6 @@ declare global { * * `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 - * `queryBy*` APIs search for an element and returns null if nothing found - * `queryAllBy*` APIs search for all elements and return empty array 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 @@ -233,34 +113,6 @@ declare global { * * `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 - * `queryBy*` APIs search for an element and returns null if nothing found - * `queryAllBy*` APIs search for all elements and return empty array 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 - */ - queryByTestId(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 - * `queryBy*` APIs search for an element and returns null if nothing found - * `queryAllBy*` APIs search for all elements and return empty array 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 - */ - queryAllByTestId(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 - * `queryBy*` APIs search for an element and returns null if nothing found - * `queryAllBy*` APIs search for all elements and return empty array 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 @@ -272,8 +124,6 @@ declare global { * * `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 - * `queryBy*` APIs search for an element and returns null if nothing found - * `queryAllBy*` APIs search for all elements and return empty array 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 @@ -285,34 +135,6 @@ declare global { * * `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 - * `queryBy*` APIs search for an element and returns null if nothing found - * `queryAllBy*` APIs search for all elements and return empty array 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 - */ - queryByTitle(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 - * `queryBy*` APIs search for an element and returns null if nothing found - * `queryAllBy*` APIs search for all elements and return empty array 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 - */ - queryAllByTitle(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 - * `queryBy*` APIs search for an element and returns null if nothing found - * `queryAllBy*` APIs search for all elements and return empty array 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 @@ -324,8 +146,6 @@ declare global { * * `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 - * `queryBy*` APIs search for an element and returns null if nothing found - * `queryAllBy*` APIs search for all elements and return empty array 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 @@ -337,34 +157,6 @@ declare global { * * `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 - * `queryBy*` APIs search for an element and returns null if nothing found - * `queryAllBy*` APIs search for all elements and return empty array 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 - */ - queryByDisplayValue(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 - * `queryBy*` APIs search for an element and returns null if nothing found - * `queryAllBy*` APIs search for all elements and return empty array 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 - */ - queryAllByDisplayValue(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 - * `queryBy*` APIs search for an element and returns null if nothing found - * `queryAllBy*` APIs search for all elements and return empty array 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 @@ -376,8 +168,6 @@ declare global { * * `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 - * `queryBy*` APIs search for an element and returns null if nothing found - * `queryAllBy*` APIs search for all elements and return empty array 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 @@ -389,34 +179,6 @@ declare global { * * `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 - * `queryBy*` APIs search for an element and returns null if nothing found - * `queryAllBy*` APIs search for all elements and return empty array 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 - */ - queryByRole(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 - * `queryBy*` APIs search for an element and returns null if nothing found - * `queryAllBy*` APIs search for all elements and return empty array 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 - */ - queryAllByRole(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 - * `queryBy*` APIs search for an element and returns null if nothing found - * `queryAllBy*` APIs search for all elements and return empty array 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 @@ -428,8 +190,6 @@ declare global { * * `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 - * `queryBy*` APIs search for an element and returns null if nothing found - * `queryAllBy*` APIs search for all elements and return empty array 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 diff --git a/types/test.ts b/types/test.ts index 4339e8d..bcf5e16 100644 --- a/types/test.ts +++ b/types/test.ts @@ -23,30 +23,3 @@ cy.findAllByTestId('foo') // $ExpectType Chainable> cy.findAllByTitle('foo') // $ExpectType Chainable> cy.findAllByDisplayValue('foo') // $ExpectType Chainable> cy.findAllByRole('foo') // $ExpectType Chainable> - -// queryBy* -cy.queryByPlaceholderText('foo') // $ExpectType Chainable> -cy.queryByText('foo') // $ExpectType Chainable> -cy.queryByLabelText('foo') // $ExpectType Chainable> -cy.queryByAltText('foo') // $ExpectType Chainable> -cy.queryByTestId('foo') // $ExpectType Chainable> -cy.queryByTitle('foo') // $ExpectType Chainable> -cy.queryByDisplayValue('foo') // $ExpectType Chainable> -cy.queryByRole('foo') // $ExpectType Chainable> - -// queryAllBy* -cy.queryAllByPlaceholderText('foo') // $ExpectType Chainable> -cy.queryAllByText('foo') // $ExpectType Chainable> -cy.queryAllByLabelText('foo') // $ExpectType Chainable> -cy.queryAllByAltText('foo') // $ExpectType Chainable> -cy.queryAllByTestId('foo') // $ExpectType Chainable> -cy.queryAllByTitle('foo') // $ExpectType Chainable> -cy.queryAllByDisplayValue('foo') // $ExpectType Chainable> -cy.queryAllByRole('foo') // $ExpectType Chainable> - -// with container option -const container = document.createElement('div') -cy.queryAllByRole('foo', { container }) // $ExpectType Chainable> - -const $container = cy.$$('body').append('div') -cy.queryAllByRole('foo', { container: $container }) // $ExpectType Chainable> From 6e134955441786a7a97e54380f3c9a512fc1b3f7 Mon Sep 17 00:00:00 2001 From: Iosif Psychas <3214876+TheGallery@users.noreply.github.com> Date: Tue, 18 Aug 2020 21:32:49 +0100 Subject: [PATCH 6/6] Add typescript as a dev dependency --- package.json | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/package.json b/package.json index 17fe556..9166fa8 100644 --- a/package.json +++ b/package.json @@ -47,7 +47,8 @@ "cypress": "^4.2.0", "dtslint": "^3.6.14", "kcd-scripts": "^5.5.0", - "npm-run-all": "^4.1.5" + "npm-run-all": "^4.1.5", + "typescript": "^3.9.7" }, "peerDependencies": { "cypress": "^2.1.0 || ^3.0.0 || ^4.0.0"