As I explore AngularJS examples online to grasp its functionality, I am attempting to test using Jasmine as demonstrated in the examples. In my spec file, I have:
var Person = function (name, $log) {
this.eat = function (food) {
$log.info(name + " is eating delicious " + food);
};
this.beHungry = function (reason) {
$log.warn(name + " hungry " + reason);
};
};
var bob = new Person();
describe("describe", function () {
it("$q", function () {
var pizzaOrderFulfillment = $q.defer();
var pizzaDelivered = pizzaOrderFulfillment.promise;
pizzaDelivered.then(bob.eat, bob.beHungry);
pizzaOrderFulfillment.resolve("resolved");
$rootScope.$digest();
expect($log.TypeInfo.logs).toContain(["resolved"]);
});
});
I encountered
ReferenceError: $q is not defined
It appears that I may be misusing Jasmine. Currently, I am writing all my Angular and Jasmine code within the spec.js file. Previously, when I had the Angular code in a separate file, my spec.js file couldn't locate it. This is likely due to a lack of setting dependencies for proper loading order, as I am just beginning to delve into this realm.
Edit, corrected the mistake of not referencing $q properly which caused the ReferenceError.