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

View File

@@ -13,10 +13,10 @@ describe Budgets::BudgetComponent do
render_inline Budgets::BudgetComponent.new(budget)
within(".budget-header") do
expect(page).to have_content("PARTICIPATORY BUDGETS")
expect(page).to have_content(budget.name)
expect(page).to have_link("Help with participatory budgets")
page.find(".budget-header") do |header|
expect(header).to have_content "Participatory budgets"
expect(header).to have_content budget.name
expect(header).to have_link "Help with participatory budgets"
end
end

View File

@@ -7,9 +7,9 @@ describe Budgets::SubheaderComponent do
render_inline Budgets::SubheaderComponent.new(budget)
within(".budget-subheader") do
expect(page).to have_content "CURRENT PHASE"
expect(page).to have_content "Information"
page.find(".budget-subheader") do |subheader|
expect(subheader).to have_content "Current phase"
expect(subheader).to have_content "Information"
end
end