jasmine-rails. It works great and you should definitely use it.
I deployed a bug
Yesterday I deployed to production a very embarrassing JS bug. It was embarrassing because it was logged in the console, and it was in the Homepage. I mean: you had to do nothing particular to find it, it was just there in the first page of my application. It was not preventing it from working, otherwise my system tests would have caught it, but it was presenting an annoying red cross.
Catch JS errors in system tests
“Why can’t I catch it in my system tests?” I thought. And I decided to add this to my
config.after(:each, type: :system, js: true) do
errors = page.driver.browser.manage.logs.get(:browser)
errors.each do |error|
expect(error.level).not_to eq('SEVERE'), error.message
next unless error.level == 'WARNING'
This script has been tested with headless_chrome and Capybara and it
- Makes your test fail for each SEVERE error message logged in the console, printing the message.
Here is a real-world example of the output of a system test I had already in place for the homepage:
👏 Nice! Our test is failing because of the JS error and is also printing me a warning about another issue.
After running the whole suite of my system tests I could catch more errors and warnings and easily fix all of them.
Hope you find this helpful!