Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Testing CSS Transition finished in Jasmine

I'm trying to test a bit of JavaScript using jasmine & jasmine-jquery

So I have this bit of Javascript in function

trackTransition = ()->
  $("#test").on "transitionend MSTransitionEnd webkitTransitionEnd oTransitionEnd", ()-> 
    console.log "trans End"

I've applied some styes in spec.css that add a css transition and added some html into a fixture, then added in the jasmine specs like so:

   describe "Checks when animation finished", ->
      beforeEach ->
        @trans = spyOnEvent('#test', 'transitionend MSTransitionEnd webkitTransitionEnd oTransitionEnd')
        jasmine.Clock.useMock()
        trackTransition()

      it "Should check when transition ended", ->
        expect(@trans).not.toHaveBeenTriggered()
        jasmine.Clock.tick(1001)
        expect(@trans).toHaveBeenTriggered()

Now I have tested this on the page and fires fine, but on runner it fails and even the console.log doesn't run. Can you test the transitions?

like image 320
DJ Forth Avatar asked May 02 '13 13:05

DJ Forth


People also ask

What's the difference between transition and Transform?

Transition is described as 'the process or a period of changing from one state or condition to another'. Transformation on the other hand is 'a marked change in form, nature, or appearance'. A subtle but important difference.

What is difference between transition and Transform in CSS?

So, what's the difference between CSS Transform and CSS Transition? The Transform property in CSS moves or modifies the appearance of an element, whereas the Transition property seamlessly and gently transitions the element from one state to another.

How transformations and Transitions can be effected in CSS?

Specify the Speed Curve of the Transitionlinear - specifies a transition effect with the same speed from start to end. ease-in - specifies a transition effect with a slow start. ease-out - specifies a transition effect with a slow end. ease-in-out - specifies a transition effect with a slow start and end.

What is the transition and Transform with example?

At their most basic level, transforms move or change the appearance of an element, while transitions make the element smoothly and gradually change from one state to another.


1 Answers

This cant work cause jasmine.Clock doesn't change the time or make the test to wait for 1000ms. It just overwrites window.setTimeout. So whenever you call setTimeout(someFunction, 1000) it saved the passed functions and times. Then when you call tick it just calls any saved functions with a time lower then the you passed to the tick call.

So the only way to test your transitionEnd event is to trigger the event manually. Also it makes not much sense to test that the event is fired after a specific time, as this is a browser behavior you rely on.

like image 120
Andreas Köberle Avatar answered Sep 21 '22 22:09

Andreas Köberle