linemanjs / lineman

Lineman helps you build fat-client JavaScript apps. It produces happiness by building assets, mocking servers, running specs on every file change
MIT License
1.18k stars 83 forks source link

Directive Unit tests (TESMEM) fail using templateUrl #386

Open ghost opened 8 years ago

ghost commented 8 years ago

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

  3. 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 commented 8 years ago

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.