0

The function I want to test is asynchronous, This function is present in a class.

Do I need to create a mock/stub to test this function?If yes then how to create one?

delayedAlert(message: string, time: number, cb){
             return setTimeout(()=>{
                cb(message)},3000)}

//calling this function shows the asynchronous behavior successfully.
Aditya
  • 2,358
  • 6
  • 35
  • 61
  • Google finds this easily "async test jasmine" https://metabroadcast.com/blog/asynchronous-testing-with-jasmine – JGFMK Jul 26 '17 at 10:23
  • yes, I saw that article before posting this question. But my question is different I suppose. – Aditya Jul 26 '17 at 10:28

1 Answers1

0

A popular library for stubbing a function or an API is Sinon. The documentation has lots of help around creating a stub, and how to test it. This can then be used in conjunction with something like Mocha to run some async tests.

Gary Stevens
  • 693
  • 8
  • 20