meteor-velocity / velocity-helpers

Testing helpers for Meteor apps to make common testing tasks straight forward.
MIT License
7 stars 0 forks source link

Meteor.Call Spy on server and client. #1

Closed samhatoum closed 9 years ago

samhatoum commented 9 years ago

I currently do this way:

// append an isolator object to Meteor to hold objects for us
Meteor._isolator = {
  calls : []
};

// add a reset method for tests to call prior to using the isolator
Meteor._isolator.reset = function() {
  Meteor._isolator.calls = [];
};

// keep track of the original call method
Meteor._isolator.call = Meteor.call;

// override the call method and...
Meteor.call = function () {

  // keep hold of the entire call so we can access them later
  Meteor._isolator.calls.push(arguments);

  // call the original method as usual
  return Meteor._isolator.call.apply(this, arguments);

};
};
samhatoum commented 9 years ago

I would like to use this using a jest-like interface:

expect(Meteor.calls[0].length).to.be.(1)

or:

expect(Meteor.calls).to.have.been.called(0).times expect(Meteor.calls).to.have.been.calledWith('someCall')

ghost commented 9 years ago

With Jasmine this is how you do this:

beforeEach(function () {
  spyOn(Meteor, 'call').and.callThrough();
});

Full documentation for spyOn

samhatoum commented 9 years ago

doh!

samhatoum commented 9 years ago

I knew that :p