Reputation: 141
I'm trying to figure out how exactly to implement this functionality of Poltergeist into my existing Capybara tests, and I'm not having any luck after reading the documentation here: https://github.com/teampoltergeist/poltergeist
I have included the below code, but when I run my tests I'm not seeing any warning about JS errors when I know there are JS errors in the console. Am I missing something? Do I have to pass in a specific command in the terminal in order to make sure this checks for JS errors? Thanks!
require 'capybara/poltergeist'
Capybara.javascript_driver = :poltergeist
options = {js_errors: true}
Capybara.register_driver :poltergeist do |app|
Capybara::Poltergeist::Driver.new(app, options)
end
Upvotes: 7
Views: 3041
Reputation: 113
I ran into your posting after I googled a similar question. In my case I had started with webkit as driver in capybara. I had read a blog post that suggested the following code , which used "have_errors" matcher to capture any js error.
it 'should not have JavaScript errors', js: true do
visit(root_path)
expect(page).to_not have_errors
end
In the event you are referring to something similar, you do not need to use any specific method to check when you are using poltergeist. You can see my code that shows what I have switched.
https://github.com/alaghu/learn_jquery/compare/dev...1d6be6dfd500
Basically, every test will automatically check if the page has errors. I only had to introduce js: true in my tests. I have verified this by intentionally erroring js files to validate these tests.
Hope this was helpful.
Upvotes: 2