Teoman shipahi Teoman shipahi - 1 year ago 684
AngularJS Question

TypeError: module is not a function AngularJS & Jasmine

In my sample app have I test runner like this

<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<script src="../../../Scripts/angular.min.js"></script>
<img src="../../../Content/jasmine/jasmine_favicon.png" />
<link href="../../../Content/jasmine/jasmine.css" rel="stylesheet" />
<script src="../../../Scripts/jasmine/jasmine.js"></script>
<script src="../../../Scripts/jasmine/jasmine-html.js"></script>
<script src="../../../Scripts/jasmine/boot.js"></script>
<!--angular mocks-->
<script src="../../../Scripts/angular-mocks.js"></script>
<!--app tests-->
<script src="../../FavoritesController.js"></script>
<script src="FavoritesController.Tests.js"></script>


var module = angular.module('AngularSampleApp', []);
var FavoritesController = module.controller('FavoritesController', function favoritesController($scope) {
$scope.phones = [
'name': 'Nexus S',
'snippet': 'Fast just got faster with Nexus S.'
'name': 'Motorola XOOMâ„¢ with Wi-Fi',
'snippet': 'The Next, Next Generation tablet.'
'name': 'MOTOROLA XOOMâ„¢',
'snippet': 'The Next, Next Generation tablet.'



describe('FavoritesController', function () {
it('should create "phones" model with 3 phones', inject(function ($controller) {
var scope = {},
ctrl = $controller('FavoritesController', { $scope: scope });


But I am getting:

TypeError: module is not a function

error after I run my tests. Am I missing something?

Answer Source

You need to include angular-mocks.js after Jasmine otherwise functions like module or inject will not be defined.

Moreover you redefine module:

var module = angular.module('AngularSampleApp', []);

So either you rename the variable or put the code inside an IIFE.