-
Hey! class Elements::FlashComponent < ViewComponent::Base
def initialize(*)
super
end
def flash_class(level)
case level
when "notice"
"alert alert-info"
when "success"
"alert alert-success"
when "error"
"alert alert-danger"
when "alert"
"alert alert-warning"
end
end
end and i'd like to test it with rspec test require "rails_helper"
RSpec.describe Elements::FlashComponent, type: :component do
it "renders flash notification" do
with_controller_class Customer::DashboardController do
flash.now[:notice] = "Notification message!"
render_inline described_class.new()
end
expect(rendered_component).to have_text "Notification message!"
expect(rendered_component).to have_selector "label"
expect(rendered_component).not_to have_selector "img"
end
end But every time I run tests I see the following message
how to fix it? |
Beta Was this translation helpful? Give feedback.
Answered by
boardfish
Jan 13, 2022
Replies: 1 comment 4 replies
-
I'd hazard a guess that Haven't tried that myself, but it's my best guess. Hope it's helpful to you! |
Beta Was this translation helpful? Give feedback.
4 replies
Answer selected by
alec-c4
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I'd hazard a guess that
flash
is a method on the controller instance. The block doesn't seem to be running in the context of the controller, so perhaps you need to callcontroller.flash
instead offlash
?Haven't tried that myself, but it's my best guess. Hope it's helpful to you!