angularjs - Avoid duplicating templates while testing my app's views in angular/karma -


i have following jasmine code:

describe('mymodel', function() {     var $scope, template;     var restservice;     var myselector = 'tr';     beforeeach(function() {         template = angular.element(                      'my' +                      'duplicated' +                      'template');         module('mymodule');         inject(function($injector, $controller, $rootscope, $compile) {                 restservice = $injector.get('restservice');                 $scope = $rootscope.$new();                 $compile(template)($scope);                 $scope.$digest();                 controller = $controller("myctrl", {$scope: $scope, restservice: restservice})         })     });      it('should list elements default', function() {         $scope.$apply();         expect(template.find(myselector).length).toequal(restservice.mocks.length);         expect($scope.skills).toequal(restservice.mocks);     }); }); 

this working fine.

the problem can't 'import' template use in application , have dupplicate in spec, very hard mantain.

i have found project https://github.com/karma-runner/karma-html2js-preprocessor can't make work. didn't find many examples on web. tried copying html2js.js projects javascripts karma complaints don't recognizing require() function @ first line of html2js.

any guidelines??

related link: how can use html fixtures karma test runner using qunit?

another option use html2js preprocessor, altering basepath in karma.conf.js.

this preprocessor appears available on default karma setup, when yeoman used bootstrap project.

this article provides more details.

http://newtriks.com/2013/04/26/how-to-test-an-angularjs-directive/


Comments

Popular posts from this blog

linux - Does gcc have any options to add version info in ELF binary file? -

android - send complex objects as post php java -

charts - What graph/dashboard product is facebook using in Dashboard: PUE & WUE -