2014-09-04 97 views
14

我有一個使用了poltergeist和水豚的大型測試套件。我不斷收到以下錯誤:當js_errors:false時,Poltergeist會拋出JS錯誤

One or more errors were raised in the Javascript code on the page. If you don't care about 
these errors, you can ignore them by setting js_errors: false in your Poltergeist 
configuration (see documentation for details). 

我很確定我設置了js_errors:false,但我仍然收到錯誤。我意識到最佳解決方案是修復JS,但我繼承了遺留代碼,修復了錯誤超出了我的角色範圍。我的規範助手文件看起來像這樣:

ENV["RAILS_ENV"] ||= 'test' 
require File.expand_path("../../config/environment", __FILE__) 
require 'rspec/rails' 
require 'rspec/autorun' 
require 'capybara/poltergeist' 
Capybara.javascript_driver = :poltergeist 

Capybara.register_driver :poltergeist do |app| 
    Capybara::Poltergeist::Driver.new(app, {js_errors: false}) 
end 

Capybara.current_driver = :poltergeist 

Capybara.configure do |config| 
    config.match = :one 
    config.exact_options = true 
    config.ignore_hidden_elements = true 
    config.visible_text_only = true 
end 

Dir[Rails.root.join("spec/support/**/*.rb")].each {|f| require f} 



RSpec.configure do |config| 
    config.infer_base_class_for_anonymous_controllers = false 
    config.order = "random" 
end 

我很困惑要去哪裏或者我是否忽略了JS錯誤。讓我知道是否有其他任何我可能忽略或忽略的信息。謝謝你的時間。

回答

24

我不確定爲什麼你的代碼不起作用。我也有類似的JS錯誤,並做了以下(上this page提到(搜索js_errors)) - 基本上什麼萊昂納多Galani建議(我upvoted萊昂納多的回答是採取從-1到0):

require 'capybara/poltergeist' 
Capybara.javascript_driver = :poltergeist 

options = {js_errors: false} 
Capybara.register_driver :poltergeist do |app| 
    Capybara::Poltergeist::Driver.new(app, options) 
end 

我還測試了這種風格,和它的工作還有:

Capybara.register_driver :poltergeist do |app| 
    Capybara::Poltergeist::Driver.new(app, {js_errors: false}) 
end 

FWIW:我的錯誤(黃瓜測試)是這樣的:

Capybara::Poltergeist::JavascriptError: One or more errors were raised in the 
Javascript code on the page. If you don't care about these errors, you can ignore 
them by setting js_errors: false in your Poltergeist configuration (see 
documentation for details). 

TypeError: Unable to delete property. 
TypeError: Unable to delete property. 
    at :84 
    at http://maps.gstatic.com/cat_js/maps-api-v3/api/js/17/20/%7Bmain,geometry%7D.js:19 in Ke 
    at http://maps.gstatic.com/cat_js/maps-api-v3/api/js/17/20/%7Bmain,geometry%7D.js:19 in Ke 
    at http://maps.gstatic.com/cat_js/maps-api-v3/api/js/17/20/%7Bmain,geometry%7D.js:18 
-2

如果您僅使用register_driver的一個選項,則不需要散列。

另外你也不是js_errors:false而是:js_errors => false 或者你可以在外面設置散列,這樣你可以添加更多的選項,如果你將來需要的話。

options = {:js_errors => false} 
Capybara.register_driver :poltergeist do |app| 
    Capybara::Poltergeist::Driver.new(app, options) 
end 
+0

您能否在答案中添加更多解釋? – 2014-11-12 20:40:27

+5

這與問題本身的代碼完全相同。 1.8.7 hashrocket語法:key => value與key:value相同。 – HaaR 2015-02-27 11:51:12

+2

這個答案有誤導性。 ':js_errors => false'與'js_errors:false'相同。然而刪除選項散列中的其他參數,只是包括這一個修正了我的錯誤。 – Sean 2015-04-14 09:41:49

3

@Leonardo Galani

根據ruby風格指南,您的語法評論是不正確的。所以答案也可以是{js_errors:false}。

https://github.com/bbatsov/ruby-style-guide#hash-literals

+1

下次再添加一個評論:) – Sean 2015-04-14 09:42:22

+1

@Sean由於缺乏聲譽,這是不可能的,但感謝您的注意。 (至少50,評論其他人的帖子) – LiveNL 2015-04-14 13:40:43

相關問題