mardi 31 mars 2015

Angular-ui-tooltip unit testing (Jasmine)

I'm trying to test my directive (it calls angular tooltip when text truncates). Angular appends tooltip to body, so I want to trigger mouseover event and check body tag for 'div.tooltip'. But nothing happens, 'div.tooltip' doesn't append.


here some code:





beforeEach(angular.mock.inject(function($rootScope, $compile) {
el = angular.element(
"<div class='test' style='width:50px' kx-tooltip-if-truncated='{{text}}'></div>"
);
$body = $('body');
$body.append(el);
bodyScope = $rootScope.$new();
bodyScope.text = 'text 96874198796871987187118718';
$compile(el)(bodyScope);
bodyScope.$apply();
pTooltip = el.find('p[tooltip]');
scope = el.scope();
}));


it('tracks directive correct initialization', function() {
expect(pTooltip.text()).toEqual(bodyScope.text);
}); //this works fine, everything that needed appended (see in html section)


it('tests long-text append tooltip', function() {
el.find('p').trigger('mouseover');
console.log($body.find('div.tooltip')[0])//find nothing and this div doesn't appended

});



<div class="test ng-scope ng-isolate-scope" style="width:50px" kx-tooltip-if-truncated="text 96874198796871987187118718">
<p tooltip="text 96874198796871987187118718"
tooltip-placement="bottom"
tooltip-append-to-body="true"
tooltip-trigger="click"
class="u-text-truncate ng-scope">
text 96874198796871987187118718
</p>
</div>

<!--that's what my directive append--!>



Aucun commentaire:

Enregistrer un commentaire