我有以下指令来自动对焦字段:
.directive('ngAutofocus', function ($timeout) {
return {
restrict: 'A',
link: function (scope, elm) {
$timeout(function () {
elm[0].focus();
});
}
};
}
Run Code Online (Sandbox Code Playgroud)
我该如何对此进行单元测试?我尝试了几个像下面的选择器,但它们都返回错误或错误:
console.log($(elm[0]).is(':focus'));
Run Code Online (Sandbox Code Playgroud)
我的单元测试设置如下:
elm = angular.element('<input type="text" name="textfield1" ng-autofocus>');
$scope.$digest();
$compile(elm)($scope);
Run Code Online (Sandbox Code Playgroud)