Skip to content

Instantly share code, notes, and snippets.

@peterellisjones
Created January 29, 2015 14:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save peterellisjones/288992fcf2e1e70df003 to your computer and use it in GitHub Desktop.
Save peterellisjones/288992fcf2e1e70df003 to your computer and use it in GitHub Desktop.
Unit testing external library calls in Meteor
# example class / prototype to test on the client
class ClientThing
clientFoo: ->
Meteor.call 'serverFoo', 'bar'
# client-side test
describe 'ClientThing', ->
clientThing = new ClientThing()
describe '#clientFoo', ->
it 'calls serverFoo with "bar"', (test) ->
# use spies to test external library calls
# https://atmospherejs.com/practicalmeteor/sinon
sinon.spy(Meteor, 'call')
clientThing.clientFoo()
test.isTrue Meteor.call.calledWith('bar')
Meteor.call.restore()
# on the server, just delegate Meteor.methods to well-tested methods
class ServerThing
serverFoo: (message) ->
console.log message
serverThing = new ServerThing()
Meteor.methods
serverFoo: (message) ->
# don't put logic here since it's untested
serverThing.serverFoo(message)
# unit-test ServerThing#serverFoo rather than Meteor.methods
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment