【发布时间】:2017-05-18 05:48:50
【问题描述】:
我正在尝试使用 RSpec 功能测试来测试我的 rails 应用程序。我将 Quilljs 用于富文本,只是想测试创建帖子的能力。
# erb view
<div id="post-form-container">
<%= form_for :post, url: posts_path, html: {id: 'post-form'} do |f| %>
<div class="form-group">
<%= f.hidden_field :discussion_id, value: discussion.id %>
<%= f.hidden_field :content, class: 'form-control', id: 'post-content-input' %>
<div id="editor-container"></div>
<%= f.button 'Post', class: 'btn btn-primary', id: 'post-button' %>
</div>
<% end %>
</div>
# spec
scenario 'can post in discussion', :js do
login_as user
visit community_group_path(community_group)
within('form#post-form') do
find('div[contenteditable="true"].ql-editor').send_keys 'This is a new post.'
click_on 'Post'
end
expect(page).to have_content 'This is a new post.'
end
This question 引导我尝试上述方法,但运行此场景时,即使使用 :js 标记,Quill 似乎也没有创建 contenteditable div。
Capybara::ElementNotFound:
Unable to find css "div[contenteditable]"
更新: 我开始意识到我需要像下面那样允许 Quill 的外部 URL,但它仍然无法正常工作。
Capybara::Webkit.configure do |config|
config.allow_url("https://cdn.quilljs.com/*")
end
更新 2:我让我的应用程序 JS 异步加载,这导致了问题。把它改成这个就行了!
<%= javascript_include_tag 'application', 'data-turbolinks-track' => true, async: Rails.env.production? %>
【问题讨论】:
标签: rspec capybara capybara-webkit quill