0
在另一个令人兴奋的“你在做什么,tbm?”的安装中,我有一个测试(肯定是在[变化]之前但现在通过)由于尽管所有努力都证明了其他方面,但仍然存在明显的阶级。即使班级不存在,角度hasClass也会返回true
上下文:
加入者的列表被显示,其中的每一个可以被分级或评分。在参赛者的分区内,相关(按类别)参赛者以摘要形式展示。直到参赛者本身通过自己的div进行评分后,才会显示摘要参赛者的评分。该测试验证了这种行为。
测试:
it('related items are hidden until scored', function() {
expect(judgeService.entrants[2].rating.score).toBe(0);
var other = angular.element(element.find('.competition')[0]);
var score_container = other.find('div > div');
expect(score_container.hasClass('ng-hide')).toBe(true);
judgeService.entrants[2].rating.score = 3;
scope.$digest();
// We'll refer to this later
console.log('HTML: ' + other.html());
console.log('CLASS: ' + score_container.attr('class'));
// failure here
expect(score_container.hasClass('ng-hide')).toBe(false);
});
HTML:
<div class="competition"
ng-repeat="other in item.related">
<div>
{{ other.name }}<br/>
<!-- this becomes the div > div in the test -->
<score-block item="other" ng-show="other.rating.score"></score-block>
</div>
</div>
输出:
LOG: 'HTML:
<div class="ng-binding">
Andres<br>
<div class="ng-isolate-scope" ng-class="{error: vm.error}" item="other" ng-show="other.rating.score">
[ skippy bits ]'
LOG: 'CLASS: ng-isolate-scope'
所以,是的,这个类不存在的元素..所以为什么hasClass( )认为它是?
[变化]
每混帐平分,这导致测试失败开始的变化是一个不相关的指令。但即使变化是直接相关的,我也没有看到hasClass()如何将每个类都报告为缺失。
更新:
通过jQuery代码挖掘(hasClass()如果使用jQuery的安装)似乎element.hasClass(“富”)将于如果任何元素的子元素有类“返回true富“,即使元素本身没有。 WTF,jQuery?