Use page.find instead of within in component tests

In component tests, the `within` method is actually an alias to RSpec's
`be_within` matcher, which is used to test numeric ranges. That meant
the tests always passed, even when there were bugs on the page.

In order to use `within` in component tests, we have to use
`page.within`. However, that also fails, since there's no such method
for `Capybara::Node::Simple'` objects, which are used in component
tests.

So we're using `page.find` instead.

See also pull request 945 in https://github.com/github/view_component
This commit is contained in:
Javi Martín
2021-09-17 02:32:08 +02:00
parent 973e9acf11
commit 57fcdc402d
3 changed files with 10 additions and 10 deletions

View File

@@ -33,9 +33,9 @@ describe Admin::BudgetsWizard::Headings::GroupSwitcherComponent do
expect(page).to have_content "Showing headings from the Parks group"
expect(page).to have_button "Manage headings from a different group"
within "button + ul" do
expect(page).to have_link "Recreation"
expect(page).to have_link "Entertainment"
page.find("button + ul") do |list|
expect(list).to have_link "Recreation"
expect(list).to have_link "Entertainment"
end
end
end