diff --git a/.all-contributorsrc b/.all-contributorsrc index 55d1b05..2ff0486 100644 --- a/.all-contributorsrc +++ b/.all-contributorsrc @@ -38,6 +38,17 @@ "code", "test" ] + }, + { + "login": "npeterkamps", + "name": "Peter Kamps", + "avatar_url": "https://avatars1.githubusercontent.com/u/25429764?v=4", + "profile": "https://github.com/npeterkamps", + "contributions": [ + "code", + "doc", + "ideas" + ] } ], "repoType": "github" diff --git a/.gitignore b/.gitignore index 5713cd4..11f40c6 100644 --- a/.gitignore +++ b/.gitignore @@ -5,6 +5,7 @@ dist .opt-out .DS_Store .eslintcache +.idea/ # these cause more harm than good # when working with contributors diff --git a/README.md b/README.md index 21b193f..bbb59b0 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-3-orange.svg?style=flat-square)](#contributors) +[![All Contributors](https://img.shields.io/badge/all_contributors-4-orange.svg?style=flat-square)](#contributors) [![PRs Welcome][prs-badge]][prs] [![Code of Conduct][coc-badge]][coc] @@ -73,6 +73,7 @@ To show some simple examples (from [cypress/integration/commands.spec.js](cypres cy.getAllByText('Jackie Chan').click() cy.queryByText('Button Text').should('exist') cy.queryByText('Non-existing Button Text').should('not.exist') +cy.queryByLabelText('Label text', { timeout: 7000 }).should('exist') ``` ## Other Solutions @@ -85,11 +86,9 @@ here! 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") | -| :---: | :---: | :---: | - +| [
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") | +| :---: | :---: | :---: | :---: | This project follows the [all-contributors][all-contributors] specification. diff --git a/src/__tests__/__snapshots__/commands.js.snap b/src/__tests__/__snapshots__/commands.js.snap index 3b142b5..dbebdc9 100644 --- a/src/__tests__/__snapshots__/commands.js.snap +++ b/src/__tests__/__snapshots__/commands.js.snap @@ -26,5 +26,9 @@ Array [ "queryAllByTitle", "getByTitle", "getAllByTitle", + "queryByValue", + "queryAllByValue", + "getByValue", + "getAllByValue", ] `; diff --git a/src/index.js b/src/index.js index fa4da0d..b9fa208 100644 --- a/src/index.js +++ b/src/index.js @@ -1,15 +1,23 @@ import {queries, waitForElement} from 'dom-testing-library' +const defaults = { + timeout: 3000, +} + const commands = Object.keys(queries).map(queryName => { return { name: queryName, command: (cy, ...args) => { + const lastArg = args[args.length - 1] + const waitOptions = (typeof lastArg === 'object') + ? Object.assign({}, defaults, lastArg) + : defaults + const queryImpl = queries[queryName] const baseCommandImpl = doc => - waitForElement(() => queryImpl(doc, ...args), { + waitForElement(() => queryImpl(doc, ...args), Object.assign({}, waitOptions, { container: doc, - timeout: 3000, - }) + })) let commandImpl if ( queryName.startsWith('queryBy') || @@ -32,12 +40,20 @@ const commands = Object.keys(queries).map(queryName => { )(commandImpl) return cy .window({log: false}) - .then(thenHandler) + .then({ timeout: waitOptions.timeout + 100 }, thenHandler) .then(subject => { Cypress.log({ $el: subject, name: queryName, - message: args, + message: args.filter((value) => { + if (Array.isArray(value) && value.length === 0) { + return false; + } + if (typeof value === 'object' && Object.keys(value).length === 0) { + return false; + } + return Boolean(value); + }), }) return subject })