Using test spy to record REST requests and reponse

209 views Asked by At

I am trying to use sinon.spy to record calls

beforeEach:

// Get restify JSON clinet instance
// Using rewire 
// m_jsonClient is a private field
m_jsonClient =  myMod.__get__('m_jsonClient')
jsonClientGetSpy = sandbox.spy(m_jsonClient, 'get')

it:

 sut.FunctionThatCallsGetMethodOfJsonClient(,,,function (err, ..) {
    jsonClientGetSpy.getCall(0).args[0] // url , i.e. /customers/123
    jsonClientGetSpy.getCall(0).args[1] // Callback Function

    // How can I access arguments?
    // If myMod uses strict mode I got
    //    TypeError: 'caller', 'callee', and 'arguments' properties 
    //    may not be accessed on strict mode functions or the arguments
    //    objects for calls to them
    // Otherwise
    //    null
    jsonClientGetSpy.getCall(0).args[1].arguments
 })

Is there possible to access "return values" in callback if spied function is not sync?

0

There are 0 answers