angular test type error

angular test type error  using -'javascript,angularjs,chai,karma-mocha'

Have tried a test case in karma, Mocha chai and sinon.

Am getting a error once I use the service. This is my error. Please any help.

PhantomJS 1.9.8 (Linux 0.0.0) Index Controller should return strong if password length is greater than equal to 8 FAILED
    TypeError: 'undefined' is not a function (evaluating 'commanService.passwordValidator("vm.password")')
        at checkPassword (/var/www/html/Testing/mocha/www/index-controller.js:14)
        at /var/www/html/Testing/mocha/www/index-controller.test.js:22
PhantomJS 1.9.8 (Linux 0.0.0): Executed 2 of 2 (1 FAILED) (0.042 secs / 0 secs)

This is my indexcontroller.js

'use strict';

angular.module('beatso.index-controller', [])
    .controller('IndexController', function(
        commanService) {
            angular.extend(vm, {
                checkPassword: checkPassword

            vm.headingTop = "Beatso A Music Fanatic Group";
            vm.password = "verystrogpassword";
            function checkPassword() {
                return commanService.passwordValidator("vm.password");

This is my test for indexcontroller.

describe('Index Controller', function() {
    var indexController;
    var commanServiceMock;
    var commanService;


    it('should return strong if password length is greater than equal to 8', function() {



    function initMocks ($provide){
        $provide.service('commanService', function(){
            return commanServiceMock;

    function initIndexController($controller) {
        indexController = $controller('IndexController');

This is my common service

'use strict';

angular.module('beatso-comman.service', [])
    .factory('commanService', function(){
        var service = {
            passwordValidator: passwordValidator

        function passwordValidator(password){
            if(password.length >= 8) {
                return 'strong'
            }else {
                return 'weak'
        return service;


asked Oct 11, 2015 by santosh soni
0 votes

Your answer

Your name to display (optional):
Privacy: Your email address will only be used for sending these notifications.
Anti-spam verification:
To avoid this verification in future, please log in or register.