Skip to content

Commit

Permalink
revert: feat: support running commands against the previous subject. (#…
Browse files Browse the repository at this point in the history
…100)

This reverts commit e32c8e4.

Reference: #109
  • Loading branch information
kentcdodds committed Jan 30, 2020
1 parent 2f62901 commit 0b73b69
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 24 deletions.
19 changes: 3 additions & 16 deletions cypress/integration/find.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -93,28 +93,15 @@ describe('find* dom-testing-library commands', () => {
)
})

it('findByText with a previous subject', () => {
cy.get('#nested')
.findByText('Button Text 1')
.should('not.exist')
cy.get('#nested')
.findByText('Button Text 2')
.should('exist')
})

it('findByText within', () => {
cy.get('#nested').within(() => {
cy.findByText('Button Text 1').should('not.exist')
cy.findByText('Button Text 2').should('exist')
cy.findByText('Button Text 2').click()
})
})

it('findByText in container', () => {
// NOTE: Cypress' `then` doesn't actually return a promise
// eslint-disable-next-line jest/valid-expect-in-promise
cy.get('#nested').then(subject => {
cy.findByText('Button Text 1', {container: subject}).should('not.exist')
cy.findByText('Button Text 2', {container: subject}).should('exist')
return cy.get('#nested').then(subject => {
cy.findByText(/^Button Text/, {container: subject}).click()
})
})

Expand Down
1 change: 0 additions & 1 deletion src/__tests__/add-commands.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ test('adds commands to Cypress', () => {
commands.forEach(({name}, index) => {
expect(addMock.mock.calls[index]).toMatchObject([
name,
{},
// We get a new function that is `command.bind(null, cy)` i.e. global `cy` passed into the first argument.
// The commands themselves will be tested separately in the Cypress end-to-end tests.
expect.any(Function),
Expand Down
4 changes: 2 additions & 2 deletions src/add-commands.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import {commands} from './'

commands.forEach(({name, command, options = {}}) => {
Cypress.Commands.add(name, options, command)
commands.forEach(({name, command}) => {
Cypress.Commands.add(name, command)
})

/* global Cypress */
7 changes: 2 additions & 5 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,18 +45,15 @@ const findCommands = findQueryNames.map(queryName => {
function createCommand(queryName, implementationName) {
return {
name: queryName,
options: {prevSubject: ['optional', 'document', 'element', 'window']},
command: (prevSubject, ...args) => {
command: (...args) => {
const lastArg = args[args.length - 1]
const defaults = getDefaultCommandOptions()
const waitOptions =
typeof lastArg === 'object' ? {...defaults, ...lastArg} : defaults

const queryImpl = queries[implementationName]
const baseCommandImpl = doc => {
const container = getContainer(
waitOptions.container || prevSubject || doc,
)
const container = getContainer(waitOptions.container || doc)
return queryImpl(container, ...args)
}
const commandImpl = doc => baseCommandImpl(doc)
Expand Down

0 comments on commit 0b73b69

Please sign in to comment.