Publication unit testing


Hi All,
I’m reading the testing guide and there is a section there about unit testing a publication.
It’s not very clear to me what are the use cases for testing a publication.
I can’t really image a test, which doesn’t only test the internal implementation of the publication, and not an app logic. In that case this is not a good unit test…
An example for that is the publication unit testing of the default “links” app of meteor.

I would love to be hear/referenced to examples which unit testing a publication is actually testing an app logic.


I tend to agree that many tests I’ve seen as examples basically just repeat the tests that MDG do when releasing updates - does all the wiring continue to work?

Business test cases are few and far between and as far as publications are concerned don’t fall into the “if I publish A, do I get A when I subscribe?” category.


I agree, this why I think I would only write unit test for publication that implement business logic (which is probably be never).


I’m unit testing publications to make sure they do things like only send data for the current user or was shared with the current user, that it doesn’t send anything when the user is not logged in.

They end up being simple, because my logic is simple, but that also makes them easy to add, so it’s still worth doing


That’s a good use case, but I think it’s more of an integration test.


“–full-app” will load all your publication

you can import collection which you want to test, then write test like what an user do normally.


  1. Meteor.loginWith user
  2. subscribe your publication
  3. test if collection has the data that u have sent with 2

same thing apply to meteor.methods

u don’t have to simulate userId to test from server side


On my publications I sometimes have search parms and limit I wanna make sure behave properly.

Also if you have publications that return more interesting stuff like contents of a folder or read other collections to feed ‘in’ statements to filter your main data source it becomes important to test them.