Currently, I'm in the process of learning how to conduct unit testing with jasmine. Despite scouring through numerous internet sources and Stack Overflow threads, I still find myself unable to resolve my particular issue.
The predicament lies within a directive containing a controller. This controller makes use of the service $uibModal to trigger a modal window upon clicking an element. My attempts to inject this service into my test have proven fruitless. Although I've come across suggestions to pass an instance, my efforts in doing so have been futile. Any assistance on this matter would be greatly appreciated.
.controller('myController', ['$scope', '$uibModal', function($scope, $uibModal){
var self = this;
//OTHER CODE
self.openMyModal = function(dataInput) {
var modalInstance = $uibModal.open({
animation: true,
bindToController: true,
templateUrl: 'app/myComponent/modals/component-modal.html',
controllerAs: 'componentModalCtrl',
controller: 'componentModalController',
windowClass: 'semi-modal semi-modal--large',
scope: $scope
})
}
//OTHER CODE
}
Here's the section of the test where I attempt to mock the modal functionality.
beforeEach(function(){
angular.mock.module('templates');
angular.mock.module('app.components.myComponent');
angular.mock.inject(function($compile, $rootScope, $templateCache, $controller){
scope = $rootScope;
modalInstance = { close: function(){}, dismiss: function(){}, open: function(){} };
//Initialize elements, perform compilation and digest
controller = $controller('myController', {$scope: scope, $uibModal: modalInstance});
})
The error message I encounter is as follows:
Unknown provider: $uibModalProvider <- $uibModal.
Is there an alternative method for injecting this service? Where could I be going wrong?
P.S: I came across this helpful discussion on Stack Overflow: Testing AngularUI Bootstrap modal instance controller
For further insight, refer to these discussions as well: Angular ui bootstrap $uibModalInstance breaks down unit tests, Mocking $modal in AngularJS unit tests