Skip to content

Commit 577290d

Browse files
NoriSteKent C. Dodds
authored andcommitted
fix(TS): Cypress commands return jQuery objects (#58) (#62)
1 parent 28414a4 commit 577290d

File tree

2 files changed

+22
-22
lines changed

2 files changed

+22
-22
lines changed

tests/typescript-types/test.spec.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
test('includes proper TypeScript types', () => {
22
cy.visit('#/foo')
33

4+
cy.getByLabelText('foo').should($elements => {
5+
expect($elements.length).to.eq(0)
6+
expect($elements[0].tagName).to.eq(0)
7+
})
8+
49
cy.getAllByPlaceholderText('foo').should($elements => {
510
expect($elements.length).to.eq(0)
611
expect($elements[0].tagName).to.eq(0)

typings/index.d.ts

Lines changed: 17 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,6 @@
11
// TypeScript Version: 2.8
22

3-
import {
4-
SelectorMatcherOptions as DTLSelectorMatcherOptions,
5-
Matcher,
6-
MatcherOptions as DTLMatcherOptions,
7-
getByTestId,
8-
} from '@testing-library/dom'
3+
import { Matcher, MatcherOptions as DTLMatcherOptions, SelectorMatcherOptions as DTLSelectorMatcherOptions } from '@testing-library/dom';
94

105
export interface CTLMatcherOptions {
116
timeout?: number
@@ -153,11 +148,11 @@ declare global {
153148
getBySelectText<E extends Node = HTMLElement>(
154149
id: Matcher,
155150
options?: MatcherOptions,
156-
): Chainable<E>
151+
): Chainable<JQuery<E>>
157152
getBySelectText<K extends keyof HTMLElementTagNameMap>(
158153
id: Matcher,
159154
options?: MatcherOptions,
160-
): Chainable<HTMLElementTagNameMap[K]>
155+
): Chainable<JQuery<HTMLElementTagNameMap[K]>>
161156

162157
/**
163158
* dom-testing-library helpers for Cypress
@@ -233,11 +228,11 @@ declare global {
233228
getByText<E extends Node = HTMLElement>(
234229
id: Matcher,
235230
options?: SelectorMatcherOptions,
236-
): Chainable<E>
231+
): Chainable<JQuery<E>>
237232
getByText<K extends keyof HTMLElementTagNameMap>(
238233
id: Matcher,
239234
options?: SelectorMatcherOptions,
240-
): Chainable<HTMLElementTagNameMap[K]>
235+
): Chainable<JQuery<HTMLElementTagNameMap[K]>>
241236

242237
/**
243238
* dom-testing-library helpers for Cypress
@@ -313,11 +308,11 @@ declare global {
313308
getByLabelText<E extends Node = HTMLElement>(
314309
id: Matcher,
315310
options?: SelectorMatcherOptions,
316-
): Chainable<E>
311+
): Chainable<JQuery<E>>
317312
getByLabelText<K extends keyof HTMLElementTagNameMap>(
318313
id: Matcher,
319314
options?: SelectorMatcherOptions,
320-
): Chainable<HTMLElementTagNameMap[K]>
315+
): Chainable<JQuery<HTMLElementTagNameMap[K]>>
321316

322317
/**
323318
* dom-testing-library helpers for Cypress
@@ -393,11 +388,11 @@ declare global {
393388
getByAltText<E extends Node = HTMLElement>(
394389
id: Matcher,
395390
options?: MatcherOptions,
396-
): Chainable<E>
391+
): Chainable<JQuery<E>>
397392
getByAltText<K extends keyof HTMLElementTagNameMap>(
398393
id: Matcher,
399394
options?: MatcherOptions,
400-
): Chainable<HTMLElementTagNameMap[K]>
395+
): Chainable<JQuery<HTMLElementTagNameMap[K]>>
401396

402397
/**
403398
* dom-testing-library helpers for Cypress
@@ -473,11 +468,11 @@ declare global {
473468
getByTestId<E extends Node = HTMLElement>(
474469
id: Matcher,
475470
options?: MatcherOptions,
476-
): Chainable<E>
471+
): Chainable<JQuery<E>>
477472
getByTestId<K extends keyof HTMLElementTagNameMap>(
478473
id: Matcher,
479474
options?: MatcherOptions,
480-
): Chainable<HTMLElementTagNameMap[K]>
475+
): Chainable<JQuery<HTMLElementTagNameMap[K]>>
481476

482477
/**
483478
* dom-testing-library helpers for Cypress
@@ -553,11 +548,11 @@ declare global {
553548
getByTitle<E extends Node = HTMLElement>(
554549
id: Matcher,
555550
options?: MatcherOptions,
556-
): Chainable<E>
551+
): Chainable<JQuery<E>>
557552
getByTitle<K extends keyof HTMLElementTagNameMap>(
558553
id: Matcher,
559554
options?: MatcherOptions,
560-
): Chainable<HTMLElementTagNameMap[K]>
555+
): Chainable<JQuery<HTMLElementTagNameMap[K]>>
561556

562557
/**
563558
* dom-testing-library helpers for Cypress
@@ -633,11 +628,11 @@ declare global {
633628
getByDisplayValue<E extends Node = HTMLElement>(
634629
id: Matcher,
635630
options?: MatcherOptions,
636-
): Chainable<E>
631+
): Chainable<JQuery<E>>
637632
getByDisplayValue<K extends keyof HTMLElementTagNameMap>(
638633
id: Matcher,
639634
options?: MatcherOptions,
640-
): Chainable<HTMLElementTagNameMap[K]>
635+
): Chainable<JQuery<HTMLElementTagNameMap[K]>>
641636

642637
/**
643638
* dom-testing-library helpers for Cypress
@@ -713,11 +708,11 @@ declare global {
713708
getByRole<E extends Node = HTMLElement>(
714709
id: Matcher,
715710
options?: MatcherOptions,
716-
): Chainable<E>
711+
): Chainable<JQuery<E>>
717712
getByRole<K extends keyof HTMLElementTagNameMap>(
718713
id: Matcher,
719714
options?: MatcherOptions,
720-
): Chainable<HTMLElementTagNameMap[K]>
715+
): Chainable<JQuery<HTMLElementTagNameMap[K]>>
721716

722717
/**
723718
* dom-testing-library helpers for Cypress

0 commit comments

Comments
 (0)