我目前正在嘗試爲通過AJAX(jQuery)加載到頁面上的收費表單編寫功能測試。它從charge_form操作加載表單,該操作返回consult_form.js.erb視圖。Rails功能測試assert_select javascript respond_to
這一切都有效,但我在測試中遇到了麻煩。
在功能上,我可以去的行動,但我不能使用assert_select找到一個元素,並驗證表單實際上在那裏。
錯誤: 1) Failure: test_should_create_new_consult(ConsultsControllerTest) [/test/functional/consults_controller_test.rb:8]: Expected at least 1 element matching "h4", found 0. <false> is not true.
這是圖。 consult_form.js.erb:
<div id="charging_form">
<h4>Charging form</h4>
<div class="left" id="charge_selection">
<%= select_tag("select_category", options_from_collection_for_select(@categories, :id, :name)) %><br/>
...
consults_controller_test.rb:
require 'test_helper'
class ConsultsControllerTest < ActionController::TestCase
def test_should_create_new_consult
get_with_user :charge_form, :animal_id => animals(:one), :id => consults(:one), :format => 'js'
assert_response :success
assert_select 'h4', "Charging form" #can't find h4
end
end
是否有使用assert_select比HTML其他類型的問題?
謝謝你的幫助!