I have a directive in angular that dynamically creates 5 buttons. I am currently writing unit tests and I decided to write one that tests if all the buttons are present. However I cannot seem to get the test to pass. Here is some of my code.
Test.js:
beforeEach(inject(function($compile,$rootScope,$location,$httpBackend,$route) {
location = $location;
scope = $rootScope.$new();
route = $route;
$httpBackend.whenGET('partials/options/options-skeleton.html')
.respond(200);
elm = angular.element("<options></options>");
leader.html').respond('200')
httpBackend = $httpBackend;
$compile(elm)(scope);
scope.$digest();
}));
describe('initial value test', function(){
it('should have 5 buttons', function(){
var options = elm.find('li');
expect(options.length).to.equal(5);
});
});
Directive html:
<div class="row row-100" style=";margin-bottom: 20px">
<div style="" class="small-12 medium-4 large-4 columns">
<ul id="options-button-wrapper">
<li ng-repeat="option in options.optionsArray track by $index">
<md-button aria-label="{{option}}" class="md-raised option-button" md-theme="green" ng-disabled="disableAllOptions">{{option}}</md-button>
</li>
</ul>
</div>
</div>
The output I keep getting is:
AssertionError: expected 0 to equal 5
I have tried using JSON.stringify() on var options in the test to see what element it was set to but I kept getting an error:
TypeError: JSON.stringify cannot serialize cyclic structures.
Any and all help would be greatly appreciated. And if anymore code is needed please just let me know and I will update my question. Thanks in advance.
Aucun commentaire:
Enregistrer un commentaire