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?
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.
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.
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.
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With