[英]Unit test: simulate the click event of child component in parent using enzyme
[英]Simulate 'click' in Angular unit test
我的Angular指令定義對象中具有以下鏈接函數:
function link(scope, element) {
var blurred = angular.element(element[0].getElementsByClassName('blur'));
blurred.on('click', function() {
blurred.css({'-webkit-filter': 'none'});
});
}
我正在嘗試測試'-webkit-filter': 'none'
在使用以下測試單擊“模糊”元素時,將'-webkit-filter': 'none'
作為樣式添加。 我的問題是兩個console.log都是相同的。 我期望永遠不會添加的樣式。
it('should add the necessary style when clicked', function() {
var blurred = angular.element(element[0].getElementsByClassName('blur'));
console.log(blurred);
blurred.triggerHandler('click');
console.log(blurred);
});
在兩種情況下,記錄的值都看起來像這樣:
{0: <div class="blur ng-binding">
<br>
<br>
</div>, length: 1}
嘗試添加單擊后的等待以避免競爭情況(如果有)
`waits(500);` // avoid race condition
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.