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:
@@ -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_content "Showing headings from the Parks group"
|
||||||
expect(page).to have_button "Manage headings from a different group"
|
expect(page).to have_button "Manage headings from a different group"
|
||||||
|
|
||||||
within "button + ul" do
|
page.find("button + ul") do |list|
|
||||||
expect(page).to have_link "Recreation"
|
expect(list).to have_link "Recreation"
|
||||||
expect(page).to have_link "Entertainment"
|
expect(list).to have_link "Entertainment"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -13,10 +13,10 @@ describe Budgets::BudgetComponent do
|
|||||||
|
|
||||||
render_inline Budgets::BudgetComponent.new(budget)
|
render_inline Budgets::BudgetComponent.new(budget)
|
||||||
|
|
||||||
within(".budget-header") do
|
page.find(".budget-header") do |header|
|
||||||
expect(page).to have_content("PARTICIPATORY BUDGETS")
|
expect(header).to have_content "Participatory budgets"
|
||||||
expect(page).to have_content(budget.name)
|
expect(header).to have_content budget.name
|
||||||
expect(page).to have_link("Help with participatory budgets")
|
expect(header).to have_link "Help with participatory budgets"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@@ -7,9 +7,9 @@ describe Budgets::SubheaderComponent do
|
|||||||
|
|
||||||
render_inline Budgets::SubheaderComponent.new(budget)
|
render_inline Budgets::SubheaderComponent.new(budget)
|
||||||
|
|
||||||
within(".budget-subheader") do
|
page.find(".budget-subheader") do |subheader|
|
||||||
expect(page).to have_content "CURRENT PHASE"
|
expect(subheader).to have_content "Current phase"
|
||||||
expect(page).to have_content "Information"
|
expect(subheader).to have_content "Information"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user