Skip to content

Commit 0b73b69

Browse files
committed
revert: feat: support running commands against the previous subject. (#100)
This reverts commit e32c8e4. Reference: #109
1 parent 2f62901 commit 0b73b69

File tree

4 files changed

+7
-24
lines changed

4 files changed

+7
-24
lines changed

cypress/integration/find.spec.js

Lines changed: 3 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -93,28 +93,15 @@ describe('find* dom-testing-library commands', () => {
9393
)
9494
})
9595

96-
it('findByText with a previous subject', () => {
97-
cy.get('#nested')
98-
.findByText('Button Text 1')
99-
.should('not.exist')
100-
cy.get('#nested')
101-
.findByText('Button Text 2')
102-
.should('exist')
103-
})
104-
10596
it('findByText within', () => {
10697
cy.get('#nested').within(() => {
107-
cy.findByText('Button Text 1').should('not.exist')
108-
cy.findByText('Button Text 2').should('exist')
98+
cy.findByText('Button Text 2').click()
10999
})
110100
})
111101

112102
it('findByText in container', () => {
113-
// NOTE: Cypress' `then` doesn't actually return a promise
114-
// eslint-disable-next-line jest/valid-expect-in-promise
115-
cy.get('#nested').then(subject => {
116-
cy.findByText('Button Text 1', {container: subject}).should('not.exist')
117-
cy.findByText('Button Text 2', {container: subject}).should('exist')
103+
return cy.get('#nested').then(subject => {
104+
cy.findByText(/^Button Text/, {container: subject}).click()
118105
})
119106
})
120107

src/__tests__/add-commands.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ test('adds commands to Cypress', () => {
1111
commands.forEach(({name}, index) => {
1212
expect(addMock.mock.calls[index]).toMatchObject([
1313
name,
14-
{},
1514
// We get a new function that is `command.bind(null, cy)` i.e. global `cy` passed into the first argument.
1615
// The commands themselves will be tested separately in the Cypress end-to-end tests.
1716
expect.any(Function),

src/add-commands.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import {commands} from './'
22

3-
commands.forEach(({name, command, options = {}}) => {
4-
Cypress.Commands.add(name, options, command)
3+
commands.forEach(({name, command}) => {
4+
Cypress.Commands.add(name, command)
55
})
66

77
/* global Cypress */

src/index.js

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -45,18 +45,15 @@ const findCommands = findQueryNames.map(queryName => {
4545
function createCommand(queryName, implementationName) {
4646
return {
4747
name: queryName,
48-
options: {prevSubject: ['optional', 'document', 'element', 'window']},
49-
command: (prevSubject, ...args) => {
48+
command: (...args) => {
5049
const lastArg = args[args.length - 1]
5150
const defaults = getDefaultCommandOptions()
5251
const waitOptions =
5352
typeof lastArg === 'object' ? {...defaults, ...lastArg} : defaults
5453

5554
const queryImpl = queries[implementationName]
5655
const baseCommandImpl = doc => {
57-
const container = getContainer(
58-
waitOptions.container || prevSubject || doc,
59-
)
56+
const container = getContainer(waitOptions.container || doc)
6057
return queryImpl(container, ...args)
6158
}
6259
const commandImpl = doc => baseCommandImpl(doc)

0 commit comments

Comments
 (0)