mercredi 28 octobre 2015

testing angularController (-method/service calls) using Jasmin

I am trying to test a small controller written in AngularJS using Jasmin.

(function() {
'use strict';
angular
    .module('bsp.account')
    .controller('Account', Account);

/* @ngInject */
function Account(userService, accountService) {

    var vm = this;

    vm.title = 'Account';

    vm.username = userService.getUsername();
    vm.showPasswordModal = accountService.showPasswordModal;
    vm.showLogoutModal = accountService.showLogoutModal;
}
})();

I want to test vm.username ,vm.showPersonModal and vm.showLogoutModal.these are all the reference to the service injected in the controller. I am fairly new and slowly trying to build my concept in testing. Below is the piece of test cases running now,

describe('Account', function() {
  var scope, controller, userServiceMock,accountServiceMock;
  beforeEach(module('bsp'));
  beforeEach(function() {
    userServiceMock = {
      getUsername: function(){} 
    };
    accountServiceMock = {
      showPasswordModal :function(){}
    };
  });

  beforeEach(inject(function($rootScope, $controller) {
    scope = $rootScope.$new();
    controller = $controller('Account', {
      'userService': userServiceMock,
      'accountService':accountServiceMock
    });
  }));

 describe('testing Title',function(){
  it('checkTitle', function(){
    expect(controller.title).toEqual('Account'); 
  });  
 });


});

Thank You for all your suggestions

Aucun commentaire:

Enregistrer un commentaire