Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove deprecated queries #152

Merged
merged 4 commits into from
Sep 3, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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