testing-library / cypress-testing-library

🐅 Simple and complete custom Cypress commands and utilities that encourage good testing practices.
http://npm.im/@testing-library/cypress
MIT License
1.8k stars 152 forks source link

Fixes #201: stop ignoring current subject when inside a .within #202

Closed istateside closed 3 years ago

istateside commented 3 years ago

What: This PR updates the getContainer util to only fallback to the withinSubject if an explicit subject has not been yielded by the previous command.

Why: The following code fails without this change:

  <section>
    <button>Button Text 1</button>
    <div id="nested">
      <button>Button Text 2</button>
    </div>
  </section>
cy.get('section').within(() => {
  cy.get('#nested').findByText(/Button Text/).should('exist');
});

How: I cloned the repo, added a new test case that failed, and then updated the util to fix the new test.

Checklist:

istateside commented 3 years ago

This PR fixes #201

istateside commented 3 years ago

@kentcdodds sorry for the ping, but could I get a review on this?

github-actions[bot] commented 3 years ago

:tada: This PR is included in version 8.0.1 :tada:

The release is available on:

Your semantic-release bot :package::rocket: