You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm currently using Inertia Rails in a new project in which we decided to use MiniTest for testing (which is also the Rails default). I noticed that Inertia Rails does not have testing support for MiniTest and wanted to ask if this feature is planned and could be implemented into the gem?
To quickly get something to work, I copied some code from the rspec integration and got some basic assertions working with the following module.
Would you be interested in merging a polished version of this into the gem? Otherwise I guess we could create a companion gem like inertia-rails-minitest.
# frozen_string_literal: truerequire"minitest/mock"moduleInertiaHelpermoduleTestWrapperincludeInertiaHelperdefrun(...)install_inertia_test_rendererdosuperendendendclassInertiaRenderWrapperattr_reader:view_data,:props,:componentdefinitialize@view_data=nil@props=nil@component=nilenddefcall(params)assign_values_from_params(params)@render_method&.(params)enddefwrap_render(render_method)@render_method=render_methodselfendprotecteddefassign_values_from_params(params)ifparams[:locals].present?@view_data=params[:locals].except(:page)@props=params[:locals][:page][:props]@component=params[:locals][:page][:component]else# Sequential Inertia request@view_data={}json=JSON.parse(params[:json])@props=json["props"]@component=json["component"]endendenddefinertia_wrap_render(render)@_inertia_render_wrapper=InertiaRenderWrapper.new.wrap_render(render)enddefinertiaassert@_inertia_render_wrapper,"The test never created an Inertia renderer. Maybe the code wasn't able to reach a `render inertia:` call?"@_inertia_render_wrapperenddefinstall_inertia_test_renderer(&)new_renderer=InertiaRails::Renderer.method(:new)new_stub=->(component,controller,request,response,render,named_args)donew_renderer.(component,controller,request,response,inertia_wrap_render(render), **named_args)endInertiaRails::Renderer.stub(:new,new_stub, &)end# Assertionsdefassert_props(**expected_props)assert_equalexpected_props,inertia.props,"Received unexpected inertia props"enddefassert_includes_props(**expected_props)assert_includesexpected_props,inertia.props,"Inertia props do not include expected props"enddefassert_component_rendered(expected_component)assert_equalexpected_component,inertia.component,"Unexpected component rendered with inertia"enddefassert_view_data(**expected_view_data)assert_equalexpected_view_data,inertia.view_data,"Received unexpected inertia view data"enddefassert_includes_view_data(**expected_view_data)assert_includesexpected_view_data,inertia.view_data,"Inertia view data does not include expected view data"endendActiveSupport.on_load(:action_dispatch_integration_test){prependInertiaHelper::TestWrapper}
The text was updated successfully, but these errors were encountered:
I'm currently using Inertia Rails in a new project in which we decided to use MiniTest for testing (which is also the Rails default). I noticed that Inertia Rails does not have testing support for MiniTest and wanted to ask if this feature is planned and could be implemented into the gem?
To quickly get something to work, I copied some code from the rspec integration and got some basic assertions working with the following module.
Would you be interested in merging a polished version of this into the gem? Otherwise I guess we could create a companion gem like
inertia-rails-minitest
.The text was updated successfully, but these errors were encountered: