Testing publications with Jasmine/Velocity

I’m wondering if it is possible to completely isolate the publish/subscribe flow in a Meteor app using Jasmine and Velocity. Right now I’m doing something like the following in Jasmine client integration mode:

    var sub;

    // Setup some fixture data in beforeEach...

    afterEach(function() {
+     if(sub) {
+       sub.stop();
+       sub = undefined;
+     }
    });
    it('publishes the latest channels', function(done) {
      sub = Meteor.subscribe('latestChannels', {
        onReady() {
          expect(Channel.getLatest().count()).toBe(10);
          done();
        }
      });
    });
  
    it('stops when trying to subscribe to my subscriptions while logged out', function(done) {
      sub = Meteor.subscribe('myChannels', {
        onReady() {
          fail('should stop');
          done();
        },
        onStop(err) {
          expect(err.error).toBe('unauthorized');
          done();
        }
      });
    });

The problem is that my homepage is already publishing “latestChannels”, so my test is not very isolated. For example, in a following test I want to test a publication that publishes a subset of “latestChannels”, but it is conflicting with my home page.

Is there a way to isolate publication code? Or possibly a way to clear all current subscriptions? I thought about maybe adding a route (I’m using FlowRouter) to my fixtures package that’s just called “blank”, and I could navigate there in my Jasmine tests before each test. That way I could be sure that no templates are messing up my subscriptions. Thoughts?

  • A route for testing that has a blank page (I call this testing sandbox) to get rid of any template subscriptions
  • Provide a way in your app to not start your global subscriptions or stop them.

Thanks! I went ahead and put in a ‘/sandbox’ route in my fixtures package.