007. 问题:在 rails5 测试中与 assert_select_rjs 相似的方法 ? - cwy007/tips-and-skills GitHub Wiki

test "should create line_item via ajax" do
    assert_difference('LineItem.count') do
      post line_items_url, params: { :product_id => products(:ruby).id }, xhr: true
    end

    assert_response :success                         # NOTE: assert_select_rjs
    # assert_select_rjs :replace_html, 'cart' do
      # assert_select 'tr#current_item td', /Programming Ruby 1.9/
    # end
  end

source: book: agile_web_dev_with_rails4

reference links: https://apidock.com/rails/ActionController/Assertions/SelectorAssertions/assert_select_rjs http://guides.rubyonrails.org/testing.html#testing-xhr-ajax-requests https://github.com/teamcapybara/capybara#asynchronous-javascript-ajax-and-friends