In Rails, how do you functional test a Javascript response format?

前端 未结 9 1035
攒了一身酷
攒了一身酷 2021-01-31 15:41

If your controller action looks like this:

respond_to do |format|
  format.html { raise \'Unsupported\' }
  format.js # index.js.erb
end

and yo

9条回答
  •  青春惊慌失措
    2021-01-31 16:31

    with rspec:

    it "should render js" do
      xhr :get, 'index'
      response.content_type.should == Mime::JS
    end
    

    and in your controller action:

    respond_to do |format|
      format.js
    end
    

提交回复
热议问题