Skip to content

Commit

Permalink
fix(TS): add timeout to MatcherOptions type (#28)
Browse files Browse the repository at this point in the history
<!--
Thanks for your interest in the project. Bugs filed and PRs submitted are appreciated!

Please make sure that you are familiar with and follow the Code of Conduct for
this project (found in the CODE_OF_CONDUCT.md file).

Also, please make sure you're familiar with and follow the instructions in the
contributing guidelines (found in the CONTRIBUTING.md file).

If you're new to contributing to open source projects, you might find this free
video course helpful: http://kcd.im/pull-request

Please fill out the information below to expedite the review and (hopefully)
merge of your pull request!
-->

<!-- What changes are being made? (What feature/bug is being fixed here?) -->

**What**:

This change adds TypeScript support for the `timeout` matcher option introduced in #7.

<!-- Why are these changes necessary? -->

**Why**:

Currently, `cypress-testing-library` uses the `MatcherOptions` interface directly from `dom-testing-library`, which does not have a `timeout` property (`timeout` is unique to `cypress-testing-library`), so using the `timeout` option throws a type error.

![image](https://user-images.githubusercontent.com/1288694/50553888-bf2ee180-0c6d-11e9-9250-a8c00c0db833.png)


<!-- How were these changes implemented? -->

**How**:

I introduced a new `CTLMatcherOptions` interface for `cypress-testing-library` specific matcher options, aliased the `MatcherOptions` import from `dom-testing-library` to `DTLMatcherOptions`, and created a new type `MatcherOptions`, a union of the two. I also added `timeout` to the existing typings test (which fails without this change).

<!-- Have you done all of these things?  -->

**Checklist**:

<!-- add "N/A" to the end of each line that's irrelevant to your changes -->

<!-- to check an item, place an "x" in the box like so: "- [x] Documentation" -->

* [ ] Documentation
* [x] Tests
* [x] Ready to be merged <!-- In your opinion, is this ready to be merged as soon as it's reviewed? -->
* [x] Added myself to contributors table <!-- this is optional, see the contributing guidelines for instructions -->

<!-- feel free to add additional comments -->

**Additional Information**:

The build was failing because the commands snapshot was outdated (new commands were added to `dom-testing-library` more recently than `cypress-testing-library` has been built on CI). I fixed the snapshot in this PR so I could progress, but let me know if you'd prefer that be separated out in its own PR and I'll split them up.
  • Loading branch information
wKovacs64 authored and Kent C. Dodds committed Dec 31, 2018
1 parent 676426c commit 18bfd99
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 2 deletions.
10 changes: 10 additions & 0 deletions .all-contributorsrc
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,16 @@
"code",
"test"
]
},
{
"login": "wKovacs64",
"name": "Justin Hall",
"avatar_url": "https://avatars1.githubusercontent.com/u/1288694?v=4",
"profile": "https://github.com/wKovacs64",
"contributions": [
"code",
"test"
]
}
],
"repoType": "github"
Expand Down
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
[![downloads][downloads-badge]][npmtrends]
[![MIT License][license-badge]][license]

[![All Contributors](https://img.shields.io/badge/all_contributors-7-orange.svg?style=flat-square)](#contributors)
[![All Contributors](https://img.shields.io/badge/all_contributors-8-orange.svg?style=flat-square)](#contributors)
[![PRs Welcome][prs-badge]][prs]
[![Code of Conduct][coc-badge]][coc]

Expand Down Expand Up @@ -102,6 +102,7 @@ Thanks goes to these people ([emoji key][emojis]):
<!-- prettier-ignore -->
| [<img src="https://avatars.githubusercontent.com/u/1500684?v=3" width="100px;"/><br /><sub><b>Kent C. Dodds</b></sub>](https://kentcdodds.com)<br />[💻](https://github.com/kentcdodds/cypress-testing-library/commits?author=kentcdodds "Code") [📖](https://github.com/kentcdodds/cypress-testing-library/commits?author=kentcdodds "Documentation") [🚇](#infra-kentcdodds "Infrastructure (Hosting, Build-Tools, etc)") [⚠️](https://github.com/kentcdodds/cypress-testing-library/commits?author=kentcdodds "Tests") | [<img src="https://avatars2.githubusercontent.com/u/498274?v=4" width="100px;"/><br /><sub><b>Ivan Babak</b></sub>](https://sompylasar.github.io)<br />[💻](https://github.com/kentcdodds/cypress-testing-library/commits?author=sompylasar "Code") [🤔](#ideas-sompylasar "Ideas, Planning, & Feedback") | [<img src="https://avatars1.githubusercontent.com/u/4002543?v=4" width="100px;"/><br /><sub><b>Łukasz Gandecki</b></sub>](http://team.thebrain.pro)<br />[💻](https://github.com/kentcdodds/cypress-testing-library/commits?author=lgandecki "Code") [⚠️](https://github.com/kentcdodds/cypress-testing-library/commits?author=lgandecki "Tests") | [<img src="https://avatars1.githubusercontent.com/u/25429764?v=4" width="100px;"/><br /><sub><b>Peter Kamps</b></sub>](https://github.com/npeterkamps)<br />[💻](https://github.com/kentcdodds/cypress-testing-library/commits?author=npeterkamps "Code") [📖](https://github.com/kentcdodds/cypress-testing-library/commits?author=npeterkamps "Documentation") [🤔](#ideas-npeterkamps "Ideas, Planning, & Feedback") [⚠️](https://github.com/kentcdodds/cypress-testing-library/commits?author=npeterkamps "Tests") | [<img src="https://avatars3.githubusercontent.com/u/4506749?v=4" width="100px;"/><br /><sub><b>Airat Aminev</b></sub>](https://github.com/airato)<br />[💻](https://github.com/kentcdodds/cypress-testing-library/commits?author=airato "Code") [⚠️](https://github.com/kentcdodds/cypress-testing-library/commits?author=airato "Tests") [🔧](#tool-airato "Tools") | [<img src="https://avatars0.githubusercontent.com/u/5121148?v=4" width="100px;"/><br /><sub><b>Adrian Smijulj</b></sub>](https://www.webiny.com)<br />[💻](https://github.com/kentcdodds/cypress-testing-library/commits?author=adrian1358 "Code") | [<img src="https://avatars0.githubusercontent.com/u/12230408?v=4" width="100px;"/><br /><sub><b>Soo Jae Hwang</b></sub>](https://www.ossfinder.com)<br />[🐛](https://github.com/kentcdodds/cypress-testing-library/issues?q=author%3Amisoguy "Bug reports") [💻](https://github.com/kentcdodds/cypress-testing-library/commits?author=misoguy "Code") [⚠️](https://github.com/kentcdodds/cypress-testing-library/commits?author=misoguy "Tests") |
| :---: | :---: | :---: | :---: | :---: | :---: | :---: |
| [<img src="https://avatars1.githubusercontent.com/u/1288694?v=4" width="100px;"/><br /><sub><b>Justin Hall</b></sub>](https://github.com/wKovacs64)<br />[💻](https://github.com/kentcdodds/cypress-testing-library/commits?author=wKovacs64 "Code") [⚠️](https://github.com/kentcdodds/cypress-testing-library/commits?author=wKovacs64 "Tests") |

<!-- ALL-CONTRIBUTORS-LIST:END -->

Expand Down
4 changes: 4 additions & 0 deletions src/__tests__/__snapshots__/commands.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@ Array [
"getAllByTitle",
"getByValue",
"getAllByValue",
"queryByDisplayValue",
"queryAllByDisplayValue",
"getByDisplayValue",
"getAllByDisplayValue",
"getAllByRole",
"getByRole",
"queryByPlaceholderText",
Expand Down
1 change: 1 addition & 0 deletions tests/typescript-types/test.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ describe('Foo', () => {
cy.queryAllByPlaceholderText<HTMLAudioElement>('foo', {
collapseWhitespace: true,
exact: true,
timeout: 500,
trim: true,
}).should(elements => {
const el = elements[0]
Expand Down
8 changes: 7 additions & 1 deletion typings/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,16 @@
import {
SelectorMatcherOptions,
Matcher,
MatcherOptions,
MatcherOptions as DTLMatcherOptions,
getByTestId,
} from 'dom-testing-library'

export interface CTLMatcherOptions {
timeout?: number
}

export type MatcherOptions = DTLMatcherOptions | CTLMatcherOptions

declare global {
namespace Cypress {
interface Chainable<Subject = any> {
Expand Down

0 comments on commit 18bfd99

Please sign in to comment.