4

I am new in jasmine testing and I have searched the test case example for requestAnimationFrame in jasmine document, but I couldn't find it.

I found this plugin to create mock requestAnimationFrame, but I need to use jasmine inbuilt option to test requestAnimationFrame.

Is there any option to test the requestAnimationFrame with jasmine using inbuilt functionalities?

Yahwe Raj
  • 1,947
  • 5
  • 25
  • 37
  • What is it about requestAnimationFrame that you would like to test? By this I mean, if you were to write this test – what would you write as the labels for the `describe` and `it` blocks? – Jamie Mason Mar 13 '17 at 14:34
  • Possible duplicate of [How to test a function which has a setTimeout with jasmine?](https://stackoverflow.com/questions/10955201/how-to-test-a-function-which-has-a-settimeout-with-jasmine) – Paul Sweatte May 30 '17 at 04:58

1 Answers1

2

Use setTimeout() and done():

it("Spec with requestAnimationFrame", (done) => {
    window.requestAnimationFrame(() => {
        // Do something testable here
    });

    setTimeout(function() {
        // Verify testable values here

        done();
    }, 200);
});
kiewic
  • 15,852
  • 13
  • 78
  • 101