How to silence JavaScript latency in Capybara acceptance tests?

My Rails application includes a JavaScript modality that appears 45 seconds after the user clicks on the link. As a result, my acceptance tests, which previously passed when there was no delay, fail.

I initially tried using the Timecop gem for faster forwarding in my Capybara acceptance test, but that didn't work. However, when I added a dream (45), it worked. Obviously, I cannot sleep (45) in my specs 3 times, but it's good to know what works, so I can get closer to this with a faster method.

From my experiments, I came to the conclusion that Ruby tracks time, and Javascript tracks time, and Timecop is Ruby's fast time, but not Javascript time. Is there a way to speed up 45 seconds rewind in my Capybara tests so that my Javascript event fires?

Here is the function that causes my tests to fail:

        $('.votable').one('click', '.vote', function() {
          $('.post-vote').
            delay(45000).
            queue(function() {
                $(this).dialog('open')
            });
        });

Again, when the delay is removed, my specifications pass, but I need the delay. How can I drown this out in Capybara tests? Or do I need to test a method using Jasmine?

+5
source share
1 answer

, .js .js.erb, , - . , , 45 , .

:

$('.votable').one('click'). '.vote', function() {
  $('.post-vote').
   <% unless Rails.env.test? %>
     delay(45000).
   <% end %>
   queue(function() {
     $(this).dialog('open')
    });
 });
+2

All Articles