Note that there are some explanatory texts on larger screens.

plurals
  1. POHow do I fake-time a jQuery animation using Sinon in a Jasmine unit test?
    primarykey
    data
    text
    <p>I have a 1 second jQuery <code>.animate</code> action that launches 5 seconds after page load. I set up a Sinon timer in my Jasmine unit testing code and test after a tick of 7 seconds to see if the post-animation properties are as they should be.</p> <p>It doesn't work right, so I've placed an instance of the animation itself on my Jasmine HTML test page to better see what's going on.</p> <ul> <li><p>In Firefox and Chrome, the page loads, the animation function is called, the unit test immediately fails, and then (also immediately) the animation visibly occurs.</p></li> <li><p>In IE, Opera and Safari, the page loads, the animation function is called, the unit test immediately fails, and the animation never visibly occurs.</p></li> </ul> <p>What I hoped for was the following (in all browsers):</p> <ul> <li>The page loads, the animation function is called, the animation completes instantaneously, and the unit test immediately succeeds.</li> </ul> <p>Looking at <a href="http://sinonjs.org/docs/#clock" rel="nofollow noreferrer">Sinon's documentation</a>, it's fake timers cover the following processes: <code>setTimeout</code>, <code>clearTimeout</code>, <code>setInterval</code>, <code>clearInterval</code>, <code>Date</code></p> <p>I don't know how jQuery's animation works, but I imagine it is using CSS to transition, and CSS transitions are not covered in Sinon's <code>useFakeTimers</code>, so I imagine this is the problem. However, if I'm right about the problem I still need a solution.</p> <p>Maybe I should try something other than Sinon? Jasmine's <code>waits()</code> works perfectly in this test, but is incredibly impractical for impatient folks like myself.</p> <p>Any other suggestions? Please keep in mind that I am new to JS unit testing, so vague answers will confuse me more than help me. ;o)</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload