Advertisement
Guest User

testCategoryCtrlResolved

a guest
Jul 1st, 2016
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. describe('Dado uma categoria', function () {
  2.  
  3.     var $controller = null;
  4.     var $factory = null;
  5.     var myScope = null;
  6.     var $httpBackend= null;
  7.     var myToastr = null;
  8.  
  9.     beforeEach(module('confsys'));
  10.  
  11.     beforeEach(inject(function (_$controller_,_CategoryFactory_,$rootScope) {
  12.         myToastr =   { success: function (message, title, options) { }, error: function (message, title, options) { } };
  13.         myScope = $rootScope.$new();
  14.         $factory = _CategoryFactory_;
  15.         $controller = _$controller_('CreateCategoryCtrl', { $scope: myScope, CategoryFactory:$factory,toastr: myToastr});
  16.     }));
  17.  
  18.     describe('Quando for criar uma categoria valída', function () {
  19.        
  20.         beforeEach(function () {
  21.             spyOn($controller,'submit').and.callThrough();
  22.             spyOn($factory,'create').and.callFake(function () {
  23.                 return{
  24.                     success:function (callBack) {
  25.                         callBack([{'id':'','name':'new category'}]);
  26.                     }
  27.                 }
  28.             });
  29.            
  30.             spyOn(myToastr,'success').and.callThrough();
  31.             spyOn(myToastr,'error').and.callThrough();
  32.                
  33.         });
  34.  
  35.         it('Então verifica se o metodo submit está implementado',function () {
  36.             expect($controller.submit).not.toBe(undefined);
  37.         });
  38.  
  39.         it('Então adiciona chamada á factory para salvar',function () {
  40.             $controller.submit();    
  41.            expect($factory.create).toHaveBeenCalled();
  42.         });
  43.  
  44.         it('Então notifica usuário que foi criado com sucesso',function () {
  45.             $controller.submit();
  46.             expect(myToastr.success).toHaveBeenCalled();
  47.         });
  48.  
  49.     });
  50. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement