Organizational Research By

Surprising Reserch Topic

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) {
        (function(vm){
            angular.extend(vm, {
                checkPassword: checkPassword
            })

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


This is my test for indexcontroller.
indeccontroller.test.js

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

    beforeEach(module('beatso.index-controller'));
    beforeEach(module(initMocks));
    beforeEach(inject(initIndexController));

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

        expect(indexController.checkPassword()).to.eql('strong');

    });


    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
5 views



Related Hot Questions



Government Jobs Opening


...