From 593264040167a0de52452802d9de169a5fc40739 Mon Sep 17 00:00:00 2001 From: Iosif Psychas <3214876+TheGallery@users.noreply.github.com> Date: Sat, 29 Aug 2020 12:09:45 +0100 Subject: [PATCH 1/4] Remove query queries and update tests --- cypress/integration/query.spec.js | 50 ------------------------------- src/__tests__/commands.js | 4 ++- src/index.js | 7 +++-- 3 files changed, 7 insertions(+), 54 deletions(-) delete mode 100644 cypress/integration/query.spec.js 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..45f4c4e 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|get)/.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..80a4129 100644 --- a/src/index.js +++ b/src/index.js @@ -5,11 +5,12 @@ function configure({fallbackRetryWithoutPreviousSubject, ...config}) { return configureDTL(config) } -const queryNames = Object.keys(queries) - -const deprecatedRegex = /^(get|query)/ +const availableRegex = /^(find|get)/ +const deprecatedRegex = /^(get)/ const findRegex = /^find/ +const queryNames = Object.keys(queries).filter(q => availableRegex.test(q)) + const deprecatedQueryNames = queryNames.filter(q => deprecatedRegex.test(q)) const findQueryNames = queryNames.filter(q => findRegex.test(q)) From 3ef88088c34c432729364b834e2033811dad5a3c Mon Sep 17 00:00:00 2001 From: Iosif Psychas <3214876+TheGallery@users.noreply.github.com> Date: Sat, 29 Aug 2020 12:35:10 +0100 Subject: [PATCH 2/4] Update documentation --- .github/ISSUE_TEMPLATE.md | 3 ++- README.md | 8 +++++--- 2 files changed, 7 insertions(+), 4 deletions(-) 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 disabled. `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. From 0e1f418d5e076ac742414485a58810616aa24fe6 Mon Sep 17 00:00:00 2001 From: Iosif Psychas <3214876+TheGallery@users.noreply.github.com> Date: Thu, 3 Sep 2020 06:29:21 +0100 Subject: [PATCH 3/4] Remove get queries --- cypress/integration/get.spec.js | 43 --------------------------------- src/__tests__/commands.js | 2 +- src/index.js | 26 ++------------------ 3 files changed, 3 insertions(+), 68 deletions(-) delete mode 100644 cypress/integration/get.spec.js 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/src/__tests__/commands.js b/src/__tests__/commands.js index 45f4c4e..c365821 100644 --- a/src/__tests__/commands.js +++ b/src/__tests__/commands.js @@ -1,7 +1,7 @@ import {queries} from '@testing-library/dom' import {commands} from '../' -const queryNames = Object.keys(queries).filter(q => /^(find|get)/.test(q)) +const queryNames = Object.keys(queries).filter(q => /^find/.test(q)) test('exports expected commands', () => { expect(commands).toMatchObject(expect.any(Array)) diff --git a/src/index.js b/src/index.js index 80a4129..1275213 100644 --- a/src/index.js +++ b/src/index.js @@ -5,30 +5,10 @@ function configure({fallbackRetryWithoutPreviousSubject, ...config}) { return configureDTL(config) } -const availableRegex = /^(find|get)/ -const deprecatedRegex = /^(get)/ const findRegex = /^find/ +const queryNames = Object.keys(queries).filter(q => findRegex.test(q)) -const queryNames = Object.keys(queries).filter(q => availableRegex.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')) }) @@ -182,8 +162,6 @@ function queryArgument(args) { return input } -const commands = [...findCommands, ...deprecatedCommands] - export {commands, configure} /* eslint no-new-func:0, complexity:0 */ From 9fda94ea7885490f495e764821cc9ae67014d6d8 Mon Sep 17 00:00:00 2001 From: Iosif Psychas <3214876+TheGallery@users.noreply.github.com> Date: Thu, 3 Sep 2020 06:32:14 +0100 Subject: [PATCH 4/4] Update README file --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 69f195e..bb84f40 100644 --- a/README.md +++ b/README.md @@ -150,7 +150,7 @@ expects DOM nodes. When you chain a query, it will get the first DOM node from `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 disabled. `find*` queries do not use the Promise API of +`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.