angularjs - $compile not compiling templates in Karma/Jasmine -
i have tested both phantomjs , chrome.
following this question i'm trying access generated html code in unit tests karma:
it('should something', inject(function ($rootscope, $templatecache, $compile) { var scope = $rootscope.$new(); scope.$digest(); var template = $templatecache.get('/app/views/mytemplate.html'); var compiler = $compile(template); var compiledtemplate = compiler(scope); console.log(compiledtemplate); }));
what i've found template being fetched correctly, , corresponds raw html file on computer. compiledtemplate never compiled correctly; basically, angular removing ng-tagged divs , replacing them comments, regardless of values should be.
for example,
<ol ng-repeat = "foo in foos"> <li>foo</li> </ol>
will replaced with:
<!-- ngrepeat: foo in foos -->
even if set scope.foos
array in unit test. have tried adding waitsfor , settimeout methods force karma wait 8 seconds, , still behavior get. i've tested css properties, , have found karma setting them correctly. example, ng-show or ng-hide div have expected css properties, directives supposed modify compiled html, being replaced comment.
is there way angular-modified dom structure of html in unit tests? is, not html angular divs removed, angular changing to?
you should $digest()
after compiling. after digest, compiledtemplate.find('ol')
(with scope.foos
array) should return ng-repeated elements.
Comments
Post a Comment