I'm starting with TDD , and am having trouble with test functions using promises , below I will list my scenario :
My Function:
(function () {
'use strict';
angular.module('com.pentaxial.utils.modais', [])
.service('Modal', ['$ionicModal', '$q', function ($ionicModal, $q) {
var self = this;
self.criar = function ($scope, template) {
var deferred = $q.defer();
if(!template) deferred.reject(new Error("Template cannot be null"));
$ionicModal.fromTemplateUrl(template, {
scope: $scope,
animation: 'slide-in-up'
}).then(function (modal) {
deferred.resolve(modal)
}, function(err){
deferred.reject(err);
});
return deferred.promise;
}
self.destruir = function (modal) {
modal.hide();
modal.remove();
return undefined;
}
}])
})();
it should be a call to excutar the self.criar test ?
I try:
it('Retorno com template definido', function(){ Modais.criar(scope, 'view/modal/cropper.html').then(function(modal){ expect(modal).toBeDefined(); },function(err){ expect(err).toBeDefined(); }) })
But not work.