diff --git a/.github/ISSUE_TEMPLATE.md b/.github/ISSUE_TEMPLATE.md index 866bf90..9613354 100644 --- a/.github/ISSUE_TEMPLATE.md +++ b/.github/ISSUE_TEMPLATE.md @@ -1,5 +1,5 @@ - - [Installation](#installation) - [With TypeScript](#with-typescript) - [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 `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. diff --git a/cypress/integration/get.spec.js b/cypress/integration/get.spec.js deleted file mode 100644 index 9c567b9..0000000 --- a/cypress/integration/get.spec.js +++ /dev/null @@ -1,43 +0,0 @@ -describe('get* queries should error', () => { - beforeEach(() => { - cy.visit('cypress/fixtures/test-app/') - }) - - const queryPrefixes = ['By', 'AllBy'] - const queryTypes = ['LabelText', 'PlaceholderText', 'Text', 'DisplayValue', 'AltText', 'Title', 'Role', 'TestId'] - - queryPrefixes.forEach(queryPrefix => { - queryTypes.forEach(queryType => { - const obsoleteQueryName = `get${queryPrefix + queryType}`; - const preferredQueryName = `find${queryPrefix + queryType}`; - it(`${obsoleteQueryName} should error and suggest using ${preferredQueryName}`, () => { - - const errorMessage = `You used '${obsoleteQueryName}' which has been removed from Cypress Testing Library because it does not make sense in this context. Please use '${preferredQueryName}' instead.` - cy.on('fail', err => { - expect(err.message).to.eq(errorMessage) - }) - - cy[`${obsoleteQueryName}`]('Irrelevant') - }) - - it(`${obsoleteQueryName} should not log more than once`, () => { - - let logCount = 0 - cy.on('log:added', (attrs, log) => { - if (log.get('name') === obsoleteQueryName) { - logCount = logCount + 1 - } - }) - - cy.on('fail', _ => { - expect(logCount).to.equal(1) - cy.removeAllListeners('log:added') - }) - - cy[`${obsoleteQueryName}`]('Irrelevant') - }) - }) - }) -}) - -/* global cy */ diff --git a/cypress/integration/query.spec.js b/cypress/integration/query.spec.js deleted file mode 100644 index 6075f89..0000000 --- a/cypress/integration/query.spec.js +++ /dev/null @@ -1,50 +0,0 @@ -describe('get* queries should error', () => { - beforeEach(() => { - cy.visit('cypress/fixtures/test-app/') - }) - - const queryPrefixes = ['By', 'AllBy'] - const queryTypes = [ - 'LabelText', - 'PlaceholderText', - 'Text', - 'DisplayValue', - 'AltText', - 'Title', - 'Role', - 'TestId', - ] - - queryPrefixes.forEach(queryPrefix => { - queryTypes.forEach(queryType => { - const obsoleteQueryName = `query${queryPrefix + queryType}` - const preferredQueryName = `find${queryPrefix + queryType}` - it(`${obsoleteQueryName} should error and suggest using ${preferredQueryName}`, () => { - const errorMessage = `You used '${obsoleteQueryName}' which has been removed from Cypress Testing Library because it does not make sense in this context. Please use '${preferredQueryName}' instead.` - cy.on('fail', err => { - expect(err.message).to.eq(errorMessage) - }) - - cy[`${obsoleteQueryName}`]('Irrelevant') - }) - - it(`${obsoleteQueryName} should not log more than once`, () => { - let logCount = 0 - cy.on('log:added', (attrs, log) => { - if (log.get('name') === obsoleteQueryName) { - logCount = logCount + 1 - } - }) - - cy.on('fail', _ => { - expect(logCount).to.equal(1) - cy.removeAllListeners('log:added') - }) - - cy[`${obsoleteQueryName}`]('Irrelevant') - }) - }) - }) -}) - -/* global cy */ diff --git a/src/__tests__/commands.js b/src/__tests__/commands.js index 86786e0..c365821 100644 --- a/src/__tests__/commands.js +++ b/src/__tests__/commands.js @@ -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 => diff --git a/src/index.js b/src/index.js index b06ddd6..1275213 100644 --- a/src/index.js +++ b/src/index.js @@ -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')) }) @@ -181,8 +162,6 @@ function queryArgument(args) { return input } -const commands = [...findCommands, ...deprecatedCommands] - export {commands, configure} /* eslint no-new-func:0, complexity:0 */