Monday, 1 May 2017

sinon - check if returned response object matches desired object

I'm using sinon spy in order to spy on HTTP response status and send. The object I return in 'send' in json like so:

{
message: 'bla bla',
fields: { request_id ='000', user_id = '3434324' } 
}

How can I checks if the returned response includes such an object, structure and values.

Here's my code:

var responseStatusSpy = sandbox.spy(res, 'status');
var responseSendSpy = sandbox.spy(res, 'send');
var response_object = {message: "invalid request - no merchant id", fields: {'request_id':'0000', 'user_id' = '2323223'}};

merchantController.getList(req, res);
responseSendSpy.withArgs ?????

Thanks in advance.



via David Faiz

No comments:

Post a Comment