Will Taylor
Will Taylor

Reputation: 2304

Rails (/Rspec) (/Capibara): Test Icon is visible?

I'm currently using Rails, Rspec and Capybara.

How would I test that an Icon is actually visible and coming through on the client side? Something like this:

<i class="ionicons ion-man"></i>

I've searched stack overflow for "Rspec Icons" and "Rails Test Icons" and haven't found an existing question that can answer this.

edit:

I don't want to show that the css is present and visible on the page, but whether the icon is coming down the asset pipeline. I just tested this solution and a passing test after 'breaking' the asset pipeline so that the icons come through as boxes. Perhaps my request is out of the ability of capybara?

Upvotes: 2

Views: 788

Answers (2)

Alireza
Alireza

Reputation: 2691

You can check if a particular node (in your case li) with a specific class (in your case ionicons) exist and is also visible:

page.has_css?('li.ionicons', :visible => true)

Upvotes: 0

Simone Carletti
Simone Carletti

Reputation: 176382

You can use the have_css selector.

expect(page).to have_css('i.ion-man')

Upvotes: 1

Related Questions