I am new to unit testing and I am getting these errors even though I though my test was correct, I just cannot figure out what these errors mean:
Can't find variable: $rootScope
Error: Injector already created, can not register a module!
spec.js
var rootScope;
beforeEach(inject(function ($injector) {
rootScope = $injector.get('$rootScope');
spyOn(rootScope, '$broadcast');
}));
describe("testing the broadcast", function () {
it("should broadcast something", function () {
$rootScope.$apply();
expect(rootScope.$broadcast).toHaveBeenCalledWith('update');
someObj = { data: testData};
expect(rootScope.$broadcast).toHaveBeenCalledWith('update', someObj);
});
});
controller
(function () {
var test= angular.module('test');
test.controller('myCtrl',
function($rootScope, $scope, $resource, $location, $route, $routeParams, $log, catalogData) {
$log.debug("myCtrl");
$log.debug(myCtrl);
$rootScope.$broadcast("update", {
data: testData
});
}); // catalogCtrl
})();
Aucun commentaire:
Enregistrer un commentaire