From 18bfd997f2aa24e24a9249aef5d34b9f4e5d0958 Mon Sep 17 00:00:00 2001 From: Justin Hall Date: Sun, 30 Dec 2018 20:17:49 -0700 Subject: [PATCH] fix(TS): add timeout to MatcherOptions type (#28) **What**: This change adds TypeScript support for the `timeout` matcher option introduced in #7. **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**: 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). **Checklist**: * [ ] Documentation * [x] Tests * [x] Ready to be merged * [x] Added myself to contributors table **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. --- .all-contributorsrc | 10 ++++++++++ README.md | 3 ++- src/__tests__/__snapshots__/commands.js.snap | 4 ++++ tests/typescript-types/test.spec.ts | 1 + typings/index.d.ts | 8 +++++++- 5 files changed, 24 insertions(+), 2 deletions(-) diff --git a/.all-contributorsrc b/.all-contributorsrc index 7b38144..aeaf46d 100644 --- a/.all-contributorsrc +++ b/.all-contributorsrc @@ -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" diff --git a/README.md b/README.md index 5a827ad..29fdcf1 100644 --- a/README.md +++ b/README.md @@ -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] @@ -102,6 +102,7 @@ Thanks goes to these people ([emoji key][emojis]): | [
Kent C. Dodds](https://kentcdodds.com)
[💻](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") | [
Ivan Babak](https://sompylasar.github.io)
[💻](https://github.com/kentcdodds/cypress-testing-library/commits?author=sompylasar "Code") [🤔](#ideas-sompylasar "Ideas, Planning, & Feedback") | [
Łukasz Gandecki](http://team.thebrain.pro)
[💻](https://github.com/kentcdodds/cypress-testing-library/commits?author=lgandecki "Code") [⚠️](https://github.com/kentcdodds/cypress-testing-library/commits?author=lgandecki "Tests") | [
Peter Kamps](https://github.com/npeterkamps)
[💻](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") | [
Airat Aminev](https://github.com/airato)
[💻](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") | [
Adrian Smijulj](https://www.webiny.com)
[💻](https://github.com/kentcdodds/cypress-testing-library/commits?author=adrian1358 "Code") | [
Soo Jae Hwang](https://www.ossfinder.com)
[🐛](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") | | :---: | :---: | :---: | :---: | :---: | :---: | :---: | +| [
Justin Hall](https://github.com/wKovacs64)
[💻](https://github.com/kentcdodds/cypress-testing-library/commits?author=wKovacs64 "Code") [⚠️](https://github.com/kentcdodds/cypress-testing-library/commits?author=wKovacs64 "Tests") | diff --git a/src/__tests__/__snapshots__/commands.js.snap b/src/__tests__/__snapshots__/commands.js.snap index 5738084..eeed656 100644 --- a/src/__tests__/__snapshots__/commands.js.snap +++ b/src/__tests__/__snapshots__/commands.js.snap @@ -28,6 +28,10 @@ Array [ "getAllByTitle", "getByValue", "getAllByValue", + "queryByDisplayValue", + "queryAllByDisplayValue", + "getByDisplayValue", + "getAllByDisplayValue", "getAllByRole", "getByRole", "queryByPlaceholderText", diff --git a/tests/typescript-types/test.spec.ts b/tests/typescript-types/test.spec.ts index 8ce8c10..16454aa 100644 --- a/tests/typescript-types/test.spec.ts +++ b/tests/typescript-types/test.spec.ts @@ -32,6 +32,7 @@ describe('Foo', () => { cy.queryAllByPlaceholderText('foo', { collapseWhitespace: true, exact: true, + timeout: 500, trim: true, }).should(elements => { const el = elements[0] diff --git a/typings/index.d.ts b/typings/index.d.ts index 8de2711..4485e9b 100644 --- a/typings/index.d.ts +++ b/typings/index.d.ts @@ -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 {