I have a file in the shared lib directory: lib/functional.js
It attaches an object F to the global scope:
F = (function() {
return {
method1: function() {}
}
})();
In the app this works fine and I can access method1 by F.method1() from everywhere, server and client.
I also have a unit test on the client that passes:
describe('GameController', function () {
beforeEach(module('blockchess'));
// Get a new controller and rootscope before each test is executed
var $controller = {};
var $scope = {};
beforeEach(inject(function (_$rootScope_, _$controller_) {
$controller = _$controller_;
$scope = _$rootScope_.$new();
}));
it('should have a gameId', function () {
$controller('GameController as ctrl', {
$scope: $scope
});
expect($scope.ctrl.game.gameId).toBe('1');
});
});
And that controller uses F.method1, and it works fine.
But in the server when I try to make a call in a unit test:
describe('Backfeed', function() {
var move = {
_id: '1'
};
var john = {
reputation: 10,
_id: '1'
};
var stars = 5;
// call protoRate
Meteor.methodMap.protoRate(john._id, move._id, stars);
expect(john.reputation).toEqual(9.47368421052632);
})
I get this error:
ReferenceError: F is not defined
/home/adam/apps/blockchess/server/lib/protocol.js:9:14: ReferenceError: F is not defined at Object.protoRate (/home/adam/apps/blockchess/server/lib/protocol.js:9:14) at /home/adam/apps/blockchess/tests/jasmine/server/unit/backfeed/backfeedSpec.js:28:22
In case it helps: I also noticed that if I remove the IIFE wrapping the F function:
F = function() {
return {
method1: function() {}
}
};
I CAN access F from the server unit test, tho it's useless through the app.
Any ideas how to get around this?