1

This is my directive

.directive('xDirective', ['x', 'y', function (x, y) {
        return {
            restrict: 'CA',
            link: function (scope, element, attrs, messaging) {
                //console.log(scope);
                //console.log(element);
                //console.log(attrs);

                if (x.isResponsive && x.responsiveMode === y.responsive.mode.phone) {

                    //set the height of the header based on the device height
                    var offset = (attrs.heightOffset ? attrs.heightOffset : 0);                    
                    element.css("height", (x.device.height - offset) + 60 + "px");
                }
            }
        };
    }])

where x and y are the dependencies to the directive..i want to unit test this directive..how do i go ahead using jasmine.

Thanks.

1 Answer 1

3

I figured it out using the below stackoverflow thread

Testing angularjs directive with dependencies

Below is the code:

describe('Directive: AppVersion', function () {
    beforeEach(module('MyApp'));

    var element;

    it('should have element text set to config value', inject(function ($rootScope, $compile, x,y) {
        var scope = $rootScope;
        element = $compile('<div class="someClass" xDirective >some Content</div>')(scope);
        expect($(element).find('.someClass').css('height')).toBe(config.version);
    }));
});

inside the it block i'm injecting 'x' and 'y' modules which are dependencies to the directive

Thanks

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.