Skip to content

Commit 848bdc0

Browse files
TheGallerykentcdodds
authored andcommitted
fix: remove deprecated queries (#152)
BREAKING CHANGE: `get` and `query` queries (which have been deprecated) have now been removed. Use `find` queries only.
1 parent 058daff commit 848bdc0

File tree

6 files changed

+12
-121
lines changed

6 files changed

+12
-121
lines changed

.github/ISSUE_TEMPLATE.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<!--
2-
HI! PLEASE STOP TO READ THIS!! If you're issue is regarding one of the query
2+
HI! PLEASE STOP TO READ THIS!! If your issue is regarding one of the query
33
APIs (`getByText`, `getByLabelText`, etc), then please file it on the
44
https://github.com/kentcdodds/dom-testing-library repository instead. If you
55
file it here it will be closed. Thanks :)
@@ -23,6 +23,7 @@ learn how: http://kcd.im/pull-request
2323
Relevant code or config
2424

2525
```javascript
26+
2627
```
2728

2829
What you did:

README.md

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,6 @@ This allows you to use all the useful
5858
<!-- START doctoc generated TOC please keep comment here to allow auto update -->
5959
<!-- DON'T EDIT THIS SECTION, INSTEAD RE-RUN doctoc TO UPDATE -->
6060

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

151-
`get*` and `query*` queries are disabled. `find*` queries do not use the Promise
152-
API of `DOM Testing Library`, but instead forward to the `get*` queries and use
150+
`query*` queries are not supported. You should use the `should('not.exist')
151+
assertion instead to check for the absence of an element.
152+
153+
`get*` queries are not supported. `find*` queries do not use the Promise API of
154+
`DOM Testing Library`, but instead forward to the `get*` queries and use
153155
Cypress' built-in retryability using error messages from `get*` APIs to forward
154156
as error messages if a query fails.
155157

cypress/integration/get.spec.js

Lines changed: 0 additions & 43 deletions
This file was deleted.

cypress/integration/query.spec.js

Lines changed: 0 additions & 50 deletions
This file was deleted.

src/__tests__/commands.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
import {queries} from '@testing-library/dom'
22
import {commands} from '../'
33

4+
const queryNames = Object.keys(queries).filter(q => /^find/.test(q))
5+
46
test('exports expected commands', () => {
57
expect(commands).toMatchObject(expect.any(Array))
6-
const sortedQueryNames = Object.keys(queries).sort()
8+
const sortedQueryNames = queryNames.sort()
79
const sortedCommandNames = commands.map(({name}) => name).sort()
810
expect(sortedCommandNames).toEqual(sortedQueryNames)
911
commands.forEach(command =>

src/index.js

Lines changed: 2 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -5,29 +5,10 @@ function configure({fallbackRetryWithoutPreviousSubject, ...config}) {
55
return configureDTL(config)
66
}
77

8-
const queryNames = Object.keys(queries)
9-
10-
const deprecatedRegex = /^(get|query)/
118
const findRegex = /^find/
9+
const queryNames = Object.keys(queries).filter(q => findRegex.test(q))
1210

13-
const deprecatedQueryNames = queryNames.filter(q => deprecatedRegex.test(q))
14-
const findQueryNames = queryNames.filter(q => findRegex.test(q))
15-
16-
const deprecatedCommands = deprecatedQueryNames.map(queryName => {
17-
return {
18-
name: queryName,
19-
command: () => {
20-
throw new Error(
21-
`You used '${queryName}' which has been removed from Cypress Testing Library because it does not make sense in this context. Please use '${queryName.replace(
22-
deprecatedRegex,
23-
'find',
24-
)}' instead.`,
25-
)
26-
},
27-
}
28-
})
29-
30-
const findCommands = findQueryNames.map(queryName => {
11+
const commands = queryNames.map(queryName => {
3112
return createCommand(queryName, queryName.replace(findRegex, 'get'))
3213
})
3314

@@ -181,8 +162,6 @@ function queryArgument(args) {
181162
return input
182163
}
183164

184-
const commands = [...findCommands, ...deprecatedCommands]
185-
186165
export {commands, configure}
187166

188167
/* eslint no-new-func:0, complexity:0 */

0 commit comments

Comments
 (0)