Meteor 1.3 full-app method tests - stubs on both client and server


Stubbed functions that are called by a Meteor method behave differently on the client and server.

This test passes on the server.

But on the client, the stub does not work and I get an error thrown by funcOne, which means that funcOne did not return true.


*Meteor 1.3-rc.4


describe 'items', ->
  describe 'addItem', ->

    item = null

    beforeEach -> 'emptyCollection', 'Items'
      item = new Item({
        name : "Thing"
        text: "Lets get this test working"

      sinon.stub utils, 'funcOne', -> true

    afterEach ->

    it 'should add an item to DB', ->'addItem', item)
      itemInDb = Items.findOne()


I have tried variations of restoring the stubbed method only on the server or not restoring at all, which does give me different errors, but still no joy.

I have looked into load order issues:

  • my tests are in the same folder as the methods - root/methods/
  • App.utils file is in root/lib/
  • I am currently not using imports/exports folders


Anybody have any ideas… Thanks.

1 Like


I solved the problem by testing Meteor.methods only on the server by wrapping them in a if Meteor.isServer. I figure that because the server is the source of truth that should be good enough. Let me know if you have any more thoughts on how best to test Meteor.methods.

1 Like