assaf/node-replay

Is there a way to know a certain stubbed service was called?

zhangchiqing opened this issue · 2 comments

I found this library is super handy for stubbing external services in my tests. But there is one thing missing (not sure if it already exists) is that how can I verify the stubbed service is being called? Further I'd like to check if was called with the right parameters.

Does this functionality already exist? Or is there workaround to do this?

Thanks!

Maybe it could be an optional to add and remove a callback with addCallback and removeCallback, so I can use them like this to verify if a service is being called with certain arguments.

var replay = require('replay');
var myservice = require('./myservice');

describe('test service', function() {
  beforeEach(function() {
     var calledWith = [];
     this.calledWith = calledWith;
     this.callback = function(called) {
        calledWith.push(called);
     };
     replay.addCallback(this.callback);
  });
  afterEach(function() {
    replay.removeCallback(this.callback);
  });
  
  it('should called with data', function() {
    var calledWith = this.calledWith;
    return myservice.getData({ id: 123 }).then(function() {
      calledWith[0].url.contains('id=123');
    });
  });
});

I found a workaround with sinon. Closing. Thanks