I have successfully managed to test a controller using jasmine through PhantomJs using Resharper 9.2 as a test runner.
To set up Resharper, I followed the instructions provided on .
The test runs smoothly if the controller does not specify the modules it is dependent on.
Controller:
var moduleName;
(function (moduleName) {
'use strict';
var testableController = (function () {
function testableController($scope) {
var _this = this;
this.$scope = $scope;
$scope.title = "Welcome";
}
testableController.className = 'testableController';
return testableController;
}());
moduleName.testableController = testableController;
})(moduleName || (moduleName = {}));
The spec file is as follows:
///<reference path="~/Scripts/jasmine/jasmine.js"/>
///<reference path="~/Scripts/jasmine/angular.js"/>
///<reference path="~/Scripts/jasmine/angular-mocks.js"/>
///<reference path="~/Scripts/angular-ui/ui-bootstrap.min.js" />
///<reference path="~/Scripts/jasmine/controllers.js"/>
///<reference path="~/Scripts/App/Controllers/testableController.js" />
///<reference path="~/Scripts/App/AppJasmine.js" />
describe("Controllers", function() {
beforeEach(module("moduleName"));
describe("Jasmine testableController", function () {
var scope,
controller;
beforeEach(inject(function ($rootScope, $controller) {
scope = $rootScope.$new();
controller = $controller('testableController', { $scope: scope });
}));
it('should set the page title as "Welcome"', function () {
expect(scope.title).toBe('Welcome');
});
});
});
When it comes to testing the controller with a dependency on Bootstrap, an error occurs.
Error: [$injector:unpr] Unknown provider: $templateRequestProvider <- $templateRequest <- $uibModal
http://errors.angularjs.org/1.2.24/$injector/unpr?p0=%24templateRequestProvider%20%3C-%20%24templateRequest%20%3C-%20%24uibModal in http://localhost:61032/referenceFile?path=~/webui/trunk/Netvacation.Pegasus.WebUI/Scripts/jasmine/angular.js (line 3802)
Controller with dependency on Bootstrap:
angular.module('moduleName', ['ui.bootstrap']);
var moduleName;
(function (moduleName) {
'use strict';
var testableController = (function () {
function testableController($scope, $uibModal) {
var _this = this;
this.$scope = $scope;
this.$uibModal = $uibModal;
$scope.title = "Welcome";
}
testableController.className = 'testableController';
return testableController;
}());
moduleName.testableController = testableController;
})(moduleName || (moduleName = {}));
**EDIT 1 ** I attempted:
beforeEach(
function () {
module("ui.bootstrap");
module("moduleName");
}
);
but encountered the same error.
Edit 2 I am using
http://angular-ui.github.io/bootstrap/ Version: 1.3.3 - 2016-05-22
AngularJS v1.2.24
Edit 3 I do not wish to test $uibModal, but rather mock it away.