Skip to content

Commit

Permalink
fix: remove deprecated queries (#152)
Browse files Browse the repository at this point in the history
BREAKING CHANGE: `get` and `query` queries (which have been deprecated) have now been removed. Use `find` queries only.
  • Loading branch information
TheGallery authored Sep 3, 2020
1 parent 55ba88b commit 2f7fc37
Show file tree
Hide file tree
Showing 6 changed files with 12 additions and 121 deletions.
3 changes: 2 additions & 1 deletion .github/ISSUE_TEMPLATE.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<!--
HI! PLEASE STOP TO READ THIS!! If you're issue is regarding one of the query
HI! PLEASE STOP TO READ THIS!! If your issue is regarding one of the query
APIs (`getByText`, `getByLabelText`, etc), then please file it on the
https://github.com/kentcdodds/dom-testing-library repository instead. If you
file it here it will be closed. Thanks :)
Expand All @@ -23,6 +23,7 @@ learn how: http://kcd.im/pull-request
Relevant code or config

```javascript

```

What you did:
Expand Down
8 changes: 5 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,6 @@ This allows you to use all the useful
<!-- START doctoc generated TOC please keep comment here to allow auto update -->
<!-- DON'T EDIT THIS SECTION, INSTEAD RE-RUN doctoc TO UPDATE -->


- [Installation](#installation)
- [With TypeScript](#with-typescript)
- [Intellisense for JavaScript with VS Code](#intellisense-for-javascript-with-vs-code)
Expand Down Expand Up @@ -148,8 +147,11 @@ expects DOM nodes. When you chain a query, it will get the first DOM node from
`subject` of the collection and use that as the `container` parameter for the
`DOM Testing Library` functions.

`get*` and `query*` queries are disabled. `find*` queries do not use the Promise
API of `DOM Testing Library`, but instead forward to the `get*` queries and use
`query*` queries are not supported. You should use the `should('not.exist')
assertion instead to check for the absence of an element.

`get*` queries are not supported. `find*` queries do not use the Promise API of
`DOM Testing Library`, but instead forward to the `get*` queries and use
Cypress' built-in retryability using error messages from `get*` APIs to forward
as error messages if a query fails.

Expand Down
43 changes: 0 additions & 43 deletions cypress/integration/get.spec.js

This file was deleted.

50 changes: 0 additions & 50 deletions cypress/integration/query.spec.js

This file was deleted.

4 changes: 3 additions & 1 deletion src/__tests__/commands.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import {queries} from '@testing-library/dom'
import {commands} from '../'

const queryNames = Object.keys(queries).filter(q => /^find/.test(q))

test('exports expected commands', () => {
expect(commands).toMatchObject(expect.any(Array))
const sortedQueryNames = Object.keys(queries).sort()
const sortedQueryNames = queryNames.sort()
const sortedCommandNames = commands.map(({name}) => name).sort()
expect(sortedCommandNames).toEqual(sortedQueryNames)
commands.forEach(command =>
Expand Down
25 changes: 2 additions & 23 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,29 +5,10 @@ function configure({fallbackRetryWithoutPreviousSubject, ...config}) {
return configureDTL(config)
}

const queryNames = Object.keys(queries)

const deprecatedRegex = /^(get|query)/
const findRegex = /^find/
const queryNames = Object.keys(queries).filter(q => findRegex.test(q))

const deprecatedQueryNames = queryNames.filter(q => deprecatedRegex.test(q))
const findQueryNames = queryNames.filter(q => findRegex.test(q))

const deprecatedCommands = deprecatedQueryNames.map(queryName => {
return {
name: queryName,
command: () => {
throw new Error(
`You used '${queryName}' which has been removed from Cypress Testing Library because it does not make sense in this context. Please use '${queryName.replace(
deprecatedRegex,
'find',
)}' instead.`,
)
},
}
})

const findCommands = findQueryNames.map(queryName => {
const commands = queryNames.map(queryName => {
return createCommand(queryName, queryName.replace(findRegex, 'get'))
})

Expand Down Expand Up @@ -181,8 +162,6 @@ function queryArgument(args) {
return input
}

const commands = [...findCommands, ...deprecatedCommands]

export {commands, configure}

/* eslint no-new-func:0, complexity:0 */
Expand Down

0 comments on commit 2f7fc37

Please sign in to comment.