相关疑难解决方法(0)

如何检查我的元素是否已集中在单元测试中

我有以下指令来自动对焦字段:

.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)

unit-testing jasmine angularjs

18
推荐指数
2
解决办法
2万
查看次数

标签 统计

angularjs ×1

jasmine ×1

unit-testing ×1