Created
July 11, 2013 17:54
-
-
Save andreibosco/5977665 to your computer and use it in GitHub Desktop.
desabilitando efeitos jQuery para testes (RSpec, Selenium, Cucumber)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Fonte: http://blog.crowdint.com/2011/04/13/turn-jquery-effects-off-for-testing.html | |
| The usual, we use RSpec for TDD, we use Cucumber for BDD, although lately, I've been using Steak in place of Cucumber and so far I am loving it. | |
| When you are using Capybara + Selenium for testing with Cucumber or Steak, sometimes you can get an error when you write tests for clicks that are followed by an animation. | |
| For example: | |
| scenario "New resource" do | |
| click_link 'New Resource' | |
| # Shows up an overlay window with the form that | |
| # takes 5 seconds to show up | |
| fill_in 'Name', :with => 'Some value' | |
| end | |
| You get the following error: | |
| Selenium::WebDriver::Error::ElementNotDisplayedError: | |
| Element is not currently visible and so may not be interacted with | |
| This happens because Capybara is trying to access the input element, but since the animation is still happening it is not visible yet. | |
| To avoid this, you can simply tell jQuery to turn off all effects when in test mode. | |
| How? Very simple. | |
| All you have to do is add this line within the <head> section of your layout. | |
| Haml | |
| = javascript_tag '$.fx.off = true;' if Rails.env.test? | |
| ERB | |
| <%= javascript_tag '$.fx.off = true;' if Rails.env.test? %> | |
| This way, every time you run your tests you will be telling jQuery to disable all effects and your test will pass, and, in some cases, even perform faster. | |
| You can read the documentation here (http://api.jquery.com/jQuery.fx.off/) for more info on how to disable jQuery effects off. | |
| Enjoy! |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment