jasmine unit test case for slider directive

256 views Asked by At

Plz see the below slider directive code

appCommon.directive('slider', [function () {
    return {
        require: 'ngModel',
        restrict: "A",
        link: function (scope, element, attr, ngModel) {

            var mySlider = element.slider({
                tooltip: 'hide',
                value: 0,
                max: 100
            });

            scope.$watch(function () {
                return ngModel.$modelValue;
            }, function (newValue, oldValue) {
                mySlider.slider('setValue', parseInt(newValue));
            });

            attr.$observe('isDisabled', function (isDisabled) {
                if (isDisabled == 'true') {
                    mySlider.slider('disable');
                }
                else {
                    mySlider.slider('enable');
                }
            });
        }
    };
}]);

and want to write unit test case for this ..could you please give me the exact test case for this

1

There are 1 answers

2
MortenJorgensen On

Dont unit test your directives. Make a controller to contain the logic, and unit test that.

controller: 'SliderController',

Add this to your directive, and move the logic you want to test to that controller.