加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > 安全 > 正文

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

发布时间:2020-12-17 07:48:05 所属栏目:安全 来源:网络整理
导读:我有以下指令来自动对焦一个字段: .directive('ngAutofocus',function ($timeout) { return { restrict: 'A',link: function (scope,elm) { $timeout(function () { elm[0].focus(); }); } };} 我将如何测试这个?我尝试了几个像下面的选择器,但都返回错误
我有以下指令来自动对焦一个字段:
.directive('ngAutofocus',function ($timeout) {
    return {
        restrict: 'A',link: function (scope,elm) {
                $timeout(function () {
                elm[0].focus();
            });
        }
    };
}

我将如何测试这个?我尝试了几个像下面的选择器,但都返回错误或者false:

console.log($(elm[0]).is(':focus'));

我的单元测试设置如下:

elm = angular.element('<input type="text"  name="textfield1" ng-autofocus>');
$scope.$digest();
$compile(elm)($scope);
我想出来,实际上很明显;
it('should set the focus on timeout',function () {
    spyOn(elm[0],'focus');
    $timeout.flush();
    expect(elm[0].focus).toHaveBeenCalled();
})

我的问题是双重的:

>我没有调用超时冲洗功能,所以超时没有发生,和>我正在尝试查看元素的focus属性,而只需要查看focus()函数的调用更像是单元测试.焦点属性是真正属于e2e测试领域的东西.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读