Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to write unit tests for server side Meteor code?

I have some server side code -- meteor methods and simple backend helpers -- that I would like to test. I've read the documentation testing with Meteor, but I am having a hard time connecting the documentation to my very simple use case. Can someone share with me how they've tested a meteor method or a simple backend JS function?

For instance, let's say you have some server method in, some_methods.js

function someHelper() {
// does lots of cool stuff
};

Meteor.methods({
  'user/update' (userProperties) {
     // updating some user properties
     someHelper();
   }
})
like image 680
robskrob Avatar asked May 30 '16 16:05

robskrob


1 Answers

We have developed unit and integration tests for our open source application called RadGrad (https://radgrad.org).

For details on how we do unit and integration testing, please see:

https://www.radgrad.org/docs/developer-guide-testing.html

Here is an example of a unit (server-side only) test:

https://github.com/radgrad/radgrad/blob/master/app/imports/api/career/CareerGoalCollection.test.js

And here is an example of an integration (client + server) test:

https://github.com/radgrad/radgrad/blob/master/app/imports/api/career/CareerGoalCollection.methods.app-test.js

We do not have extensive UI tests; you'll need to use something like Selenium for that. UI testing in Meteor is no different from UI testing for any other web app.

like image 97
Philip Johnson Avatar answered Oct 20 '22 23:10

Philip Johnson