Jasmine junit testing args delegate callback

I recently started using jasmine to record a junit test case for one of our applications. I am stuck at this point on how to call the callBack function of the spied function.

setProfile :function(userProfile,callback){ var user; var subjectInfo; iService.searchForAccess(subjectInfo , queryCalback); function queryCalback(err, userProfile) { if(err){ callback(true,errorMessage) }else{ callback(false,null) } } } 

Now, in my specification, I want to make fun of the iService.searchForAccess call of the real world and want to call nocallThrough for searchForAccess. but my queryCalback function needs to be called to cover full use.

In my specification, I tried to explicitly call the queryCalback function using

 spyOn(iService,'searchForAccess'); iService.searchForAccess.mostRecentCall.args[1](error, userProfile); 

but iService.searchForAccess.mostRecentCall returns {}, an empty object.

kindly help !!!!!!!!!!

Punith Relations

0
source share
1 answer

I used sinonjs as a solution to the above problem. The following is the syntax of how this is done.

 var sinon = require('../node_modules/sinon/lib/sinon.js'); sinon.stub(iService, 'searchForAccess').callsArgWith(1, mockSubjectInfo, session.userProfile); 

Hope this will be helpful to others.

Punith Relations

0
source

Source: https://habr.com/ru/post/1390515/


All Articles