Created
January 29, 2015 14:07
-
-
Save peterellisjones/288992fcf2e1e70df003 to your computer and use it in GitHub Desktop.
Unit testing external library calls in Meteor
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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