beforeEach(function () { html = '<div class="dropdown">'+ '<div class="trigger" >trigger</div>'+ '<div class="dropdown">body</div>'+ '<div>'; inject(function ($compile,$rootScope) { scope = $rootScope.$new(); element = angular.element(html); compiled = $compile(element); compiled(scope); scope.$digest(); // HERE NOT WORKING var trigger == element.find('div.trigger'); var dropdown == element.find('.dropdown'); // trigger and dropdown have both length 0 }); // Test doesn't pass it('should find the right element'),function () { expect(trigger.hasClass('trigger')).toBe(true); } });
我正在尝试单元测试一个指令,但是我不能逐个找到元素。
我想要找到像以下这样的元素:
var trigger == element.find('div.trigger') // doesn't find anything.
但现在我只能这样做:
var triggers = element.find('div') // return an array of length 2. var trigger = triggers[0];
我如何按类找到一个元素?