Posts

Showing posts from April, 2017

Stubbing a Javascript Generator function

Recently, I had to test a generator function, which was calling another generator function from within it. I learnt something on how to stub a generator function. (Note: Code is not tested for accuracy. The code is only used to illustrate the concept). Use case: Following is a simplified example which describes the scenario: The use case here is to check the database if a user already exists in the database. If so, the user should be added. If not the user should be added. Project Structure: Objects Functions UserDao 1)     function* findUser(userId:String):User 2)     function* saveUser(user:User):User UserHelper 1)     function* saveUser(user:User):User UserController 1)     function saveUser(user:User):User When a request is made to add the user, the request lands in the saveUser function in the UserController. The controller uses a co-generator to call the saveUser generator function i