I am trying to unit test a angular controller that contains a dataService factory. The problem is that I get the error TypeError: 'undefined' is not an object (evaluating 'myScope.data.test')
Can anyone see what I am doing wrong?
/// <reference path="../scripts/jasmine.js" />
/// <reference path="../scripts/angular.js" />
/// <reference path="../scripts/angular-mocks.js" />
var app = angular.module('myApp', []);
app.factory("dataService", ["$http", "$q", function ($http, $q) {
var _test = function () {
return "Hello world";
};
return {
test: _test,
};
}]);
var testController = ["$scope", "dataService",
function ($scope, dataService) {
$scope.data = dataService; // This is similar to a DAL
}];
describe('Tests my controller without mocks', function () {
var myScope;
var myDataService;
beforeEach(inject(function ($rootScope, $httpBackend, $controller) {
angular.module('myApp');
myScope = $rootScope.$new();
myDataService = $rootScope.dataService;
$controller('testController', {
$scope: myScope,
dataService: myDataService
});
}));
it('should say Hello', function () {
expect(myScope.data.test).toBe("Hello world");
});
});