Skip to content

Instantly share code, notes, and snippets.

@ndbroadbent
Created October 12, 2022 21:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ndbroadbent/e850ec4bb37d79b4571c311d104da39b to your computer and use it in GitHub Desktop.
Save ndbroadbent/e850ec4bb37d79b4571c311d104da39b to your computer and use it in GitHub Desktop.
Configure RSpec to crash on any JS errors or warnings
# Inspired by https://medium.com/@coorasse/catch-javascript-errors-in-your-system-tests-89c2fe6773b1
IGNORED_BROWSER_LOGS = [
'You may test your Stripe.js integration over HTTP. However, live Stripe.js integrations must use HTTPS.',
].freeze
RSpec.configure do |config|
config.after :each, js: true do
errors = page.driver.browser.manage.logs.get(:browser)
next if errors.blank?
aggregate_failures 'Browser Errors' do
errors.each do |error|
next unless %w[WARNING SEVERE].include?(error.level)
next if IGNORED_BROWSER_LOGS.any? { |msg| error.message.include?(msg) }
flunk "[Browser Logs] #{error.level}: #{error.message}"
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment