我注意到,在js請求中使用jquery方法調用中嵌入的文本將其插入到DOM中,這在Rails中很常見。如何對JavaScript響應進行功能測試?
// javascript code
$.getScript("/some_url");
// rails partial code, to make things more clear I have added some simple html
$("#some_id").text(unescape_javascript('<div id="foo">bar</div>'))
我的問題是你如何執行assert_select,或等效,在這樣的響應文本的功能測試?
//
class FooBarControllerTest < ...
test "javascript response" do
xhr :get, :new
// how could I test the div here
assert_select "#foo", "bar" // this doesn't work
end
end
**更新代碼以使其更清晰
* *作爲來自另一端的字符串,然後作爲普通腳本運行它? – FeRtoll 2011-01-31 21:27:15
是的。部分內生成的代碼將在客戶端執行。 – chris 2011-01-31 21:28:58