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

fix: make chaining take precedence over surrounding `within` block. #200

Closed yagni closed 3 years ago

yagni commented 3 years ago

What: Chaining now takes precedence over the scope defined by its surrounding within block. Only calls that don't have a previous subject and don't have a container specified use the within block.

Why: Chaining inside of a within block previously ignored the chain and searched starting at the within element. This gave incorrect (too many) results. This was touched on at the end of #132

How: Moved the use of win.document inside of getContainer() so we can be more specific about when to use it.

Checklist:

istateside commented 3 years ago

I missed this PR, and made basically the same fix in a different PR https://github.com/testing-library/cypress-testing-library/pull/202 with a smaller diff

Instead of changing what gets passed into getValue, I'm checking for whether there's an explicit subject in the current chain, with cy.state('subject'). I don't really have an opinion on which one is better, but i'll leave my PR up

I also made a separate issue for the problem, https://github.com/testing-library/cypress-testing-library/issues/201

kentcdodds commented 3 years ago

Sorry, I didn't notice this PR (I don't watch this repo). Does #202 solve this as well?

yagni commented 3 years ago

@kentcdodds Yep. I'll close this one.