Skip to content

Commit

Permalink
fix(TS): Cypress commands return jQuery objects (#58) (#62)
Browse files Browse the repository at this point in the history
  • Loading branch information
NoriSte authored and Kent C. Dodds committed Jul 19, 2019
1 parent 28414a4 commit 577290d
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 22 deletions.
5 changes: 5 additions & 0 deletions tests/typescript-types/test.spec.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
test('includes proper TypeScript types', () => {
cy.visit('#/foo')

cy.getByLabelText('foo').should($elements => {
expect($elements.length).to.eq(0)
expect($elements[0].tagName).to.eq(0)
})

cy.getAllByPlaceholderText('foo').should($elements => {
expect($elements.length).to.eq(0)
expect($elements[0].tagName).to.eq(0)
Expand Down
39 changes: 17 additions & 22 deletions typings/index.d.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,6 @@
// TypeScript Version: 2.8

import {
SelectorMatcherOptions as DTLSelectorMatcherOptions,
Matcher,
MatcherOptions as DTLMatcherOptions,
getByTestId,
} from '@testing-library/dom'
import { Matcher, MatcherOptions as DTLMatcherOptions, SelectorMatcherOptions as DTLSelectorMatcherOptions } from '@testing-library/dom';

export interface CTLMatcherOptions {
timeout?: number
Expand Down Expand Up @@ -153,11 +148,11 @@ declare global {
getBySelectText<E extends Node = HTMLElement>(
id: Matcher,
options?: MatcherOptions,
): Chainable<E>
): Chainable<JQuery<E>>
getBySelectText<K extends keyof HTMLElementTagNameMap>(
id: Matcher,
options?: MatcherOptions,
): Chainable<HTMLElementTagNameMap[K]>
): Chainable<JQuery<HTMLElementTagNameMap[K]>>

/**
* dom-testing-library helpers for Cypress
Expand Down Expand Up @@ -233,11 +228,11 @@ declare global {
getByText<E extends Node = HTMLElement>(
id: Matcher,
options?: SelectorMatcherOptions,
): Chainable<E>
): Chainable<JQuery<E>>
getByText<K extends keyof HTMLElementTagNameMap>(
id: Matcher,
options?: SelectorMatcherOptions,
): Chainable<HTMLElementTagNameMap[K]>
): Chainable<JQuery<HTMLElementTagNameMap[K]>>

/**
* dom-testing-library helpers for Cypress
Expand Down Expand Up @@ -313,11 +308,11 @@ declare global {
getByLabelText<E extends Node = HTMLElement>(
id: Matcher,
options?: SelectorMatcherOptions,
): Chainable<E>
): Chainable<JQuery<E>>
getByLabelText<K extends keyof HTMLElementTagNameMap>(
id: Matcher,
options?: SelectorMatcherOptions,
): Chainable<HTMLElementTagNameMap[K]>
): Chainable<JQuery<HTMLElementTagNameMap[K]>>

/**
* dom-testing-library helpers for Cypress
Expand Down Expand Up @@ -393,11 +388,11 @@ declare global {
getByAltText<E extends Node = HTMLElement>(
id: Matcher,
options?: MatcherOptions,
): Chainable<E>
): Chainable<JQuery<E>>
getByAltText<K extends keyof HTMLElementTagNameMap>(
id: Matcher,
options?: MatcherOptions,
): Chainable<HTMLElementTagNameMap[K]>
): Chainable<JQuery<HTMLElementTagNameMap[K]>>

/**
* dom-testing-library helpers for Cypress
Expand Down Expand Up @@ -473,11 +468,11 @@ declare global {
getByTestId<E extends Node = HTMLElement>(
id: Matcher,
options?: MatcherOptions,
): Chainable<E>
): Chainable<JQuery<E>>
getByTestId<K extends keyof HTMLElementTagNameMap>(
id: Matcher,
options?: MatcherOptions,
): Chainable<HTMLElementTagNameMap[K]>
): Chainable<JQuery<HTMLElementTagNameMap[K]>>

/**
* dom-testing-library helpers for Cypress
Expand Down Expand Up @@ -553,11 +548,11 @@ declare global {
getByTitle<E extends Node = HTMLElement>(
id: Matcher,
options?: MatcherOptions,
): Chainable<E>
): Chainable<JQuery<E>>
getByTitle<K extends keyof HTMLElementTagNameMap>(
id: Matcher,
options?: MatcherOptions,
): Chainable<HTMLElementTagNameMap[K]>
): Chainable<JQuery<HTMLElementTagNameMap[K]>>

/**
* dom-testing-library helpers for Cypress
Expand Down Expand Up @@ -633,11 +628,11 @@ declare global {
getByDisplayValue<E extends Node = HTMLElement>(
id: Matcher,
options?: MatcherOptions,
): Chainable<E>
): Chainable<JQuery<E>>
getByDisplayValue<K extends keyof HTMLElementTagNameMap>(
id: Matcher,
options?: MatcherOptions,
): Chainable<HTMLElementTagNameMap[K]>
): Chainable<JQuery<HTMLElementTagNameMap[K]>>

/**
* dom-testing-library helpers for Cypress
Expand Down Expand Up @@ -713,11 +708,11 @@ declare global {
getByRole<E extends Node = HTMLElement>(
id: Matcher,
options?: MatcherOptions,
): Chainable<E>
): Chainable<JQuery<E>>
getByRole<K extends keyof HTMLElementTagNameMap>(
id: Matcher,
options?: MatcherOptions,
): Chainable<HTMLElementTagNameMap[K]>
): Chainable<JQuery<HTMLElementTagNameMap[K]>>

/**
* dom-testing-library helpers for Cypress
Expand Down

0 comments on commit 577290d

Please sign in to comment.