Skip to content

Directive Unit tests (TESMEM) fail using templateUrl #386

@ghost

Description

Steps to reproduce

  1. Directive being tested using the standard lineman angular template:
 .directive('dlErrorValidationHandlerHelper', ['DLValidationService', '$templateCache',
        function(DLValidationService, $templateCache ) {
            return {
                scope: true,
                // I was not able to make this work with the unit tests; temnplate below did the work.
                //templateUrl: function(tElement, tAttributes) {
                //    var validationType,
                //        validationDefinitionObject,
                //        templateUrl;
                //
                //    if(!tAttributes.hasOwnProperty('validationType')) {
                //        throw "dlValidationDirective requires attribute: validationType";
                //    }
                //    validationType = tAttributes.validationType;
                //
                //    validationDefinitionObject = DLValidationService.getVDO(validationType);
                //    if(validationDefinitionObject === null) {
                //        throw "dlValidationDirective unable to find validation definition object for: " + validationType;
                //    }
                //    templateUrl = validationDefinitionObject.templateUrl;
                //    var templateUrlString = $templateCache.get(templateUrl);
                //
                //    console.log("templateUrl: " + templateUrl);
                //    console.log("templateUrlString: " + templateUrlString);
                //    return templateUrl;
                //},
                template: function(tElement, tAttributes) {
                        var validationType,
                            validationDefinitionObject,
                            templateUrl;

                        if(!tAttributes.hasOwnProperty('validationType')) {
                            throw "dlErrorValidationHandlerHelper requires attribute: validationType";
                        }
                        validationType = tAttributes.validationType;

                        validationDefinitionObject = DLValidationService.getVDO(validationType);
                        if(validationDefinitionObject === null) {
                            throw "dlErrorValidationHandlerHelper unable to find validation definition object for: " + validationType;
                        }
                        templateUrl = validationDefinitionObject.templateUrl;
                        var templateUrlString = $templateCache.get(templateUrl);

                        //console.log("templateUrl: " + templateUrl);
                        //console.log("templateUrlString: " + templateUrlString);
                        return templateUrlString;
                },
                controller: function($scope, $element, $attrs, $transclude) {
                },
                compile: function() {
                    return {
                        pre: function(scope, tElement, tAttributes) {
                        },
                        post: function(scope, iElement, iAttributes) {
                            //console.log("dlErrorValidationHandlerHelper_post: I was here");
                            scope.validationArgument = null;

                            if(iAttributes.hasOwnProperty('validationArgument')) {
                                scope.validationArgument = iAttributes.validationArgument;
                            }
                        }
                    };
                }
            };
        }
    ])

Observed behavior

  1. It does not work when using templateUrl. Note that the code is commented out.
  2. It works when using template in combination with _$templateCache.get().

Expected Behavior

  1. It works with templateUrl

I found references about how to use _ ng-html2js_ with Karma, but was not able to find similar documentation about how to configure TESTEM to use it. I suspect that it is there and that I missed it completely.

Regardless, thanks in advance for your help with this.

Regards
Rodrigo

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions