Testing: Visibility of Collections in Server Jasmine Tests


I’m starting a test suite with sanjo:jasmine and velocity:htmlreporter. As a lazy first step, I want to test simply against the database. But it’s not working. I have a Pet collection:

# shared/collections/pet.coffee
console.log "declaring Pets"
@Pet = new Mongo.Collection("pets")

Then I have my simple test:

# tests/jasmine/server/unit/simple_test.coffee
describe 'Pets', ->
  beforeEach ->
    console.log '--------------'
    pet1 = Pet.insert name: 'Fluffy', species: 'Cat', breed: 'Domestic Shorthair', dob: new Date('12/19/2003')

it 'starts out with 1 pet', ->
  petCount = Pet.find().count()

This is where I’m confused. My hope was not to have to mock or stub everything. And the remove and insert don’t produce errors, but the data is not persisted to the database because when I do the find in the first example, Pet is an object but Pet.find() returns undefined.

What am I missing about how this should lay out (BTW: If I move this to client/unit, it does work if I provide proper permissions for remove).


If you remove the test to tests/jasmine/server/integration/ it should work as you expect. In the server unit mode the collection is stubbed. This means collection.insert, collection.find etc. do nothing by default.