Note that there are some explanatory texts on larger screens.

plurals
  1. POAvoid duplicating templates while testing my app's views in angular/karma
    text
    copied!<p>I have the following jasmine code:</p> <pre><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 all elements by default', function() { $scope.$apply(); expect(template.find(mySelector).length).toEqual(restService.mocks.length); expect($scope.skills).toEqual(restService.mocks); }); }); </code></pre> <p>This is working fine.</p> <p>The problem is that I <strong>can't 'import' the template</strong> I use in the application and I have to <strong>dupplicate</strong> it in this spec, which is <strong>very hard to mantain</strong>.</p> <p>I have found this project <a href="https://github.com/karma-runner/karma-html2js-preprocessor" rel="nofollow noreferrer">https://github.com/karma-runner/karma-html2js-preprocessor</a> but I can't make it work. I didn't find many examples on the web. I tried copying html2js.js to my projects javascripts but karma complaints about don't recognizing require() function at the first line of html2js.</p> <p>Any guidelines??</p> <p>Related link: <a href="https://stackoverflow.com/questions/16209749/how-can-i-use-html-fixtures-with-karma-test-runner-using-qunit">How can I use HTML fixtures with Karma test runner using Qunit?</a></p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload