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

使用clientWidth时AngularJS单元测试错误

发布时间:2020-12-17 06:47:18 所属栏目:安全 来源:网络整理
导读:在我的代码中有一行: var contentWidth = angular.element(document.querySelector('.content'))[0].clientWidth; 它在运行应用程序时工作正常但在单元测试时出现错误: TypeError: 'undefined' is not an object (evaluating 'angular.element(document.qu
在我的代码中有一行:

var contentWidth = angular.element(document.querySelector('.content'))[0].clientWidth;

它在运行应用程序时工作正常但在单元测试时出现错误:

TypeError: 'undefined' is not an object (evaluating 'angular.element(document.querySelector('.content'))[0].clientWidth')

如何解决这个问题?

解决方法

在运行测试时附加DOM,或者在不需要相同的情况下模拟document.querySelector和angular.element.

请记住在测试完成后删除角元素上的mock / spy,因为它会干扰内部使用它的jasmine框架.

(编辑:李大同)

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

    推荐文章
      热点阅读