How to check Javascript errors using capybara and poltergeist?

I'm trying to figure out exactly how to implement this Poltergeist functionality in my existing Capybara tests, and I was out of luck after reading the documentation here: https://github.com/teampoltergeist/poltergeist

I have included the code below, but when I run my tests, I do not see a JS error warning when I know that there are JS errors in the console. Am I missing something? Do I have to pass a specific command in the terminal 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 
+6
source share
1 answer

I came across your posts after I applied a similar question. In my case, I started with webkit as a driver in capybara. I read a blog post suggesting the following code that used the has_errors match to catch any js error.

 it 'should not have JavaScript errors', js: true do visit(root_path) expect(page).to_not have_errors end 

If you are referring to something like this, you do not need to use any specific method to check when using the poltergeist. You can see my code that shows what I switched.

https://github.com/alaghu/learn_jquery/compare/dev...1d6be6dfd500

Basically, each test automatically checks for page errors. I needed to enter js: true in my tests. I checked this by deliberate js file error to validate these tests.

Hope this was helpful.

+3
source

Source: https://habr.com/ru/post/985378/


All Articles