From 390c8a89daaab49d6761af5c9c8f275e10e62c64 Mon Sep 17 00:00:00 2001 From: Jean-Baptiste Bellet Date: Fri, 9 Apr 2021 10:56:19 +0200 Subject: [PATCH] Add (very simple) spec for a ViewComponent component - Add `ViewComponent::TestHelpers` to get the helper method `render_inline` - Use Capybara to expect some assertion --- spec/components/example_component_spec.rb | 8 ++++++++ spec/spec_helper.rb | 4 ++++ 2 files changed, 12 insertions(+) create mode 100644 spec/components/example_component_spec.rb diff --git a/spec/components/example_component_spec.rb b/spec/components/example_component_spec.rb new file mode 100644 index 0000000000..0cac3d8ff5 --- /dev/null +++ b/spec/components/example_component_spec.rb @@ -0,0 +1,8 @@ +require "spec_helper" + +describe "ExampleComponent tests", type: :component do + it "displays the h1 with the given parameter" do + render_inline(ExampleComponent.new(title: "Hello")) { } + expect(page).to have_selector "h1", text: "Hello" + end +end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 39f1441214..b483c52be9 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -74,6 +74,8 @@ require "paperclip/matchers" # Override setting in Spree engine: Spree::Core::MailSettings ActionMailer::Base.default_url_options[:host] = 'test.host' +require "view_component/test_helpers" + RSpec.configure do |config| # ## Mock Framework # @@ -232,6 +234,8 @@ RSpec.configure do |config| # PerfTools::CpuProfiler.stop # end config.infer_spec_type_from_file_location! + + config.include ViewComponent::TestHelpers, type: :component end FactoryBot.use_parent_strategy = false