Skip to content

CypressError: cy.findByText() failed because it requires the subject be a global 'document' object. #114

Closed
@leosuncin

Description

@leosuncin
  • cypress-testing-library version: 5.2.0
  • node version: 13.7.0
  • npm (or yarn) version: 6.13.6

Relevant code or config

it('should validate the credentials', () => {
    cy.findByText(/Log me in/i)
      .click()
      .findByText(/Username should not be empty/i)
      .findByText(/Password should not be empty/i);
});

What you did: Bump @testing-library/cypress from 5.0.2 to 5.2.0

What happened:

  1) Register page should validate the data:                                                                                                                                                                                      [149/2152]
     CypressError: cy.findByText() failed because it requires the subject be a global 'document' object.                                                                                                                                    

The subject received was:

<span.MuiButton-label>

The previous command that ran was:

cy.click()

All 3 subject validations failed on this subject.
at Object.cypressErr (http://localhost:3000/__cypress/runner/cypress_runner.js:86207:11)
at Object.throwErr (http://localhost:3000/__cypress/runner/cypress_runner.js:86162:18)
at Object.throwErrByPath (http://localhost:3000/__cypress/runner/cypress_runner.js:86194:17)
at ensureDocument (http://localhost:3000/__cypress/runner/cypress_runner.js:74338:21)
at validateType (http://localhost:3000/__cypress/runner/cypress_runner.js:74184:16)
at Object.ensureSubjectByType (http://localhost:3000/__cypress/runner/cypress_runner.js:74210:9)
at pushSubjectAndValidate (http://localhost:3000/__cypress/runner/cypress_runner.js:81127:15)
at Context. (http://localhost:3000/__cypress/runner/cypress_runner.js:81413:18)
at http://localhost:3000/__cypress/runner/cypress_runner.js:80892:33
at tryCatcher (http://localhost:3000/__cypress/runner/cypress_runner.js:120203:23)
at Promise._settlePromiseFromHandler (http://localhost:3000/__cypress/runner/cypress_runner.js:118139:31)
at Promise._settlePromise (http://localhost:3000/__cypress/runner/cypress_runner.js:118196:18)
at Promise._settlePromiseCtx (http://localhost:3000/__cypress/runner/cypress_runner.js:118233:10)
at Async../node_modules/bluebird/js/release/async.js.Async._drainQueue (http://localhost:3000/__cypress/runner/cypress_runner.js:114933:12)
at Async../node_modules/bluebird/js/release/async.js.Async._drainQueues (http://localhost:3000/__cypress/runner/cypress_runner.js:114938:10)
at Async.drainQueues (http://localhost:3000/__cypress/runner/cypress_runner.js:114812:14)

https://github.com/leosuncin/mui-next-ts/pull/26/checks?check_run_id=421662750

Reproduction repository:

https://github.com/leosuncin/mui-next-ts/tree/dependabot/npm_and_yarn/testing-library/cypress-5.2.0

Problem description:

Suggested solution:

it('should validate the credentials', () => {
    cy.findByText(/Log me in/i)
      .click();
    cy.findByText(/Username should not be empty/i)
      .findByText(/Password should not be empty/i);
});

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingreleased

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions