Reputation: 1885
I'm working with a javascript file that a) declares an object with functions, and b) calls the init function for that object with a hash which it expects to be declared externally. My Jasmine spec is complaining that it can't find the hash, because it isn't there!
var Foo = {
init: function(param) { ... }
};
Foo.init(externalVariable);
My initial feeling is that this is badly structured and rather than just declaring the variable, the external declaration should also call the function, but let's ignore that for now.
Is there a way for me to declare this variable to Jasmine prior to it loading the source files?
Thanks
Upvotes: 2
Views: 839
Reputation: 187034
Assign the value to the global object, if it is indeed a global. Just dont forget to remove it when the test is over to keep your environment clean for your other tests.
beforeEach(function() {
window.externalVariable = "this kinda sucks";
});
afterEach(function() {
delete window.externalVariable;
});
Upvotes: 3