Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Directive Unit tests (TESMEM) fail using templateUrl #386

Open
ghost opened this issue Apr 22, 2016 · 1 comment
Open

Directive Unit tests (TESMEM) fail using templateUrl #386

ghost opened this issue Apr 22, 2016 · 1 comment

Comments

@ghost
Copy link

ghost commented Apr 22, 2016

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

@searls
Copy link
Member

searls commented Apr 22, 2016

Hi Rodrigo, heads up that I don't have much of an idea of how to fix this nor whether it's lineman or testem's responsibility to do so. We don't need this particular feature ourselves, so we're not likely to address this problem, however we would be glad to accept a tested pull request if it resolves the issue without apparent unintended consequences.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant