Slots aren't working in Rspec but are in previews and locally #1561
-
Hello, The component below works locally (and in previews), but does not work when running my Rspec suite. Here's the spec: RSpec.describe Card::Body, type: :component do
it "renders with slots" do
render_inline(described_class.new) do |component|
component.title { "Title" }
end
expect(page).to have_css("h5.card-title", text: "Title")
end
end Output: F
Failures:
1) Card::Body renders a component with slots
Failure/Error: expect(page).to have_css("h5.card-title", text: "Title")
expected to find css "h5.card-title" but there were no matches
# ./spec/components/card/body_spec.rb:12:in `block (2 levels) in <top (required)>'
# ./spec/spec_helper.rb:150:in `block (3 levels) in <top (required)>'
# ./spec/spec_helper.rb:150:in `block (2 levels) in <top (required)>' Here's my class Card::Body < ViewComponent::Base
renders_one :title, lambda { |**options|
options[:tag] = :h5
options[:classes] = class_names("card-title", options[:classes])
BaseComponent.new(**options)
}
def initialize(**options)
@options = options
@options[:tag] = :div
@options[:classes] = class_names(
"card-body",
options[:classes]
)
end
end and my class BaseComponent < ViewComponent::Base
def initialize(tag:, classes: nil, **options)
@tag = tag
@classes = classes
@options = options
end
def call
content_tag(@tag, content, class: @classes, **@options)
end
end When debugging and outputting "<div class=\"card-body\"></div>" But in previews, it's showing: <div class="card-body">
<h5 class="card-title">Card Title</h5>
</div> |
Beta Was this translation helpful? Give feedback.
Answered by
boardfish
Oct 27, 2022
Replies: 1 comment
-
Hi there @onesneakymofo! This thread may help to navigate your issue for now. |
Beta Was this translation helpful? Give feedback.
0 replies
Answer selected by
joelhawksley
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hi there @onesneakymofo! This thread may help to navigate your issue for now.