|
| 1 | +# frozen_string_literal: true |
| 2 | + |
| 3 | +require "test_helper" |
| 4 | + |
| 5 | +# The mrblib runtime is plain Ruby, so the CRuby suite can cover the |
| 6 | +# Response#body alias and the handler error report format directly; |
| 7 | +# the browser-side wiring ships with the next picoruby.wasm rebuild. |
| 8 | +class CallbackErrorVisibilityTest < Minitest::Test |
| 9 | + def setup |
| 10 | + Funicular::SSR::Runtime.load_framework! |
| 11 | + end |
| 12 | + |
| 13 | + # Assigning the anonymous class to a constant names it, so the report |
| 14 | + # prints a real component name. Defined lazily: Funicular::Component |
| 15 | + # only exists after the framework loads. |
| 16 | + def probe_component |
| 17 | + unless defined?(::CheckoutProbeComponent) |
| 18 | + Object.const_set(:CheckoutProbeComponent, Class.new(Funicular::Component) do |
| 19 | + def render; end |
| 20 | + end) |
| 21 | + end |
| 22 | + ::CheckoutProbeComponent.new |
| 23 | + end |
| 24 | + |
| 25 | + def test_response_body_is_an_alias_of_data |
| 26 | + response = Funicular::HTTP::Response.new(200, { "id" => 1 }) |
| 27 | + assert_equal response.data, response.body |
| 28 | + assert_equal({ "id" => 1 }, response.body) |
| 29 | + end |
| 30 | + |
| 31 | + def test_report_handler_error_names_component_handler_and_event |
| 32 | + error = ArgumentError.new("wrong number of arguments (given 1, expected 0)") |
| 33 | + |
| 34 | + out, _err = capture_io do |
| 35 | + probe_component.report_handler_error("click", "#handle_save", error) |
| 36 | + end |
| 37 | + |
| 38 | + assert_includes out, "CheckoutProbeComponent#handle_save" |
| 39 | + assert_includes out, "(onclick)" |
| 40 | + assert_includes out, "ArgumentError: wrong number of arguments" |
| 41 | + end |
| 42 | + |
| 43 | + def test_report_handler_error_never_raises |
| 44 | + capture_io do |
| 45 | + assert_nil probe_component.report_handler_error("click", "#x", RuntimeError.new("y")) |
| 46 | + end |
| 47 | + end |
| 48 | +end |
0 commit comments