In attempting to unit test my custom directive, I ran into an issue trying to find
an element with a dynamic class applied to it, based on an expression within an ng-class
directive. It seems to me that the expression is just not evaluating at all. Is this possible to test? And if so, what am I doing wrong or missing?
The first unit test passes fine, the second is where the issue lies.
The tests:
beforeEach(inject(function ($rootScope, $compile) {
scope = $rootScope.$new();
element = '<tp-navigation-bar></tp-navigation-bar>';
scope.currentPage = 'reports';
scope.contactName = 'Test Name';
scope.isLoggedIn = true;
element = $compile(element)(scope);
scope.$digest();
}));
it("should contain a dropdown with the contact name as the title", function () {
expect(element.find('.dropdown-toggle span:nth-child(2)').text()).toEqual('Test Name');
});
it("should have reports set as the active page", function () {
expect(element.find('li .active').text()).toEqual('Reports');
});
The template:
<ul class="nav navbar-nav navbar-right" ng-show="isLoggedIn">
<li ng-class="{active:currentPage === 'mainDashboard'}">
Home
</li>
<li ng-class="{active:currentPage === 'requests'}">
Requests
</li>
<li ng-class="{active:currentPage === 'reports'}">
Reports
</li>
</ul>
Aucun commentaire:
Enregistrer un commentaire