Skip to content

Capybara: use animation-disabling middleware#87

Merged
joshpencheon merged 1 commit intomasterfrom
capybara-disable-animation
Jan 12, 2021
Merged

Capybara: use animation-disabling middleware#87
joshpencheon merged 1 commit intomasterfrom
capybara-disable-animation

Conversation

@joshpencheon
Copy link
Contributor

Summary

Recent versions of Capybara can automatically inject an additional middleware in the test environment, that appends animation-disabling statements to the end of the <head>. This will neuter all jQuery animations, and CSS animations/transitions.

This PR enables this middleware by default, and bumps the capybara requirement to the latest release, to get the most animation-disabling potential.

This will inject something into the head of all test-env responses to
neuter all jQuery animations, and CSS animations/transitions.
@joshpencheon
Copy link
Contributor Author

Testing this with a host project, in an integration test we see:

CSS rules being injected:

/* puts Nokogiri::HTML(page.body).xpath('//head/style').text */

*, *::before, *::after {
   transition: none !important;
   animation-duration: 0s !important;
   animation-delay: 0s !important;
   scroll-behavior: auto !important;
}

And JS:

/* puts Nokogiri::HTML(page.body).xpath('//head/script').text */

(typeof jQuery !== 'undefined') && (jQuery.fx.off = true);

Copy link
Contributor

@ollietulloch ollietulloch left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @joshpencheon, looks good to me.

I've run this against a host app and tests are passing. I have also observed the below being injected:

  *, *::before, *::after {
     transition: none !important;
     animation-duration: 0s !important;
     animation-delay: 0s !important;
     scroll-behavior: auto !important;
  }

@joshpencheon joshpencheon merged commit 5b427cb into master Jan 12, 2021
@joshpencheon joshpencheon deleted the capybara-disable-animation branch January 15, 2021 16:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants