I'm trying to implement testing on my meteor application using velocity [1] and jasmine [2]. I defined a collection called 'object' (collections/object.js):
Objects = new Meteor.Collection('objects');
I implemented a set up function (tests/jasmine/server/unit/ObjectSpec.js):
describe('Objects', function () {
'use strict';
// set up
beforeEach(function () {
// 1 - backup all data
MeteorStubs.install();
// 2 - delete current 'Objects'-items
Objects.remove({});
// 3 - add test data
Objects.insert({
someProperty: 'data1'
});
});
then I do run the actual tests (same file):
// actual tests
it("should delete a specific object", function () {
var selector = {someProperty: 'data1'};
var selectedObject = Objects.findOne(selector);
// will return 'Expected undefined not to be undefined.'
expect(selectedObject).not.toBe(undefined);
Meteor.call('deleteObject', selectedObject, function(error, id) {
if (error)
return alert(error.reason);
});
expect(Objects.findOne(selector)).toBe(undefined);
});
after, I restore the old application state in the tear down (same file):
// tear down
afterEach(function () {
Objects.remove({});
MeteorStubs.uninstall();
});
Now, when executing the test, velocity throws me: Expected undefined not to be undefined.
I wonder, if the data in the 'beforeEach'-Function actually will be inserted and accessible in the actual testing function? Also, I tried using console.log() in the test functions, to show the current data, but it won't be shown in the browser console. Why?