When running SpecRunner.html, an error is encountered
ReferenceError: module is not defined
The Controller code is as follows:
angular.module('mymodule', [])
.controller('mycontroller', ['$scope',
function($scope) {
$scope.employees = [{
name: 'Dick',
address: 'Mumbai'
}, {
name: 'Tom',
address: 'US'
}];
$scope.addEmployee = function() {
$scope.employees.push({
name: $scope.name,
address: $scope.address
});
}
}
])
The associated spec file looks like this:
describe('Employee', function() {
var mycontroller, scope;
beforeEach(module('mymodule'));
beforeEach(inject(function($controller, $scope) {
scope = $rootScope;
mycontroller = $controller('mycontroller', {
$scope: scope
});
}));
it("when employee gets added", function() {
var employeecount = $scope.employees.count;
$scope.addEmployee('xxxx', 'yyy');
var employeecount1 = $scope.employees.count;
expect(employeecount + 1).toBe(employeecount1);
});
});
The content of SpecRunner.html is:
<link rel="shortcut icon" type="image/png" href="lib/jasmine-2.2.0/jasmine_favicon.png">
<link rel="stylesheet" href="lib/jasmine-2.2.0/jasmine.css">
<script src="lib/jasmine-2.2.0/jasmine.js"></script>
<script src="lib/jasmine-2.2.0/jasmine-html.js"></script>
<script src="lib/jasmine-2.2.0/boot.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.3.14/angular.min.js"></script>
<script src="../Controller.js"></script>
<script src="spec/myspec.js"></script>
Note: This is the first Unit test in jasmine.