大佬教程收集整理的这篇文章主要介绍了单元测试 – 如何在AngularJS单元测试中向DOM添加div?,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
var bodyoffset = document.querySELEctor(".smallcontainer-content").getBoundingClientRect(); var width = elm.width(); if(bodyoffset != undefined){ var tooltipDiv = document.querySELEctor(".tooltip"); angular.element(tooltipDiv).css("top",offset.top-bodyoffset.top+"px"); angular.element(tooltipDiv).css("left",offset.left-bodyoffset.left+width+5+"px"); }
这不能在单元测试中工作,因为类“smallcontainer”所在的div不存在.我如何确保在单元测试中创建div,以便我可以测试我的所有功能?
beforeEach(inject( ['$compile','$rootScope',function(_$compile_) { var html = '<div class="smallcontainer-content"></div>'; angular.element(document.body).append(html); elm = angular.element('<form name="form"><input name="password" id="passwordInput" data-ng-model="password" size="25" type="password" maxlength="20" tabindex="1" autofocus data-my-password-check></form>'); $compile(elm)($rootScopE); form = $rootScope.form; }] ));
这里将html添加到文档中的重要部分是angular.element().append().
我在http://www.yearofmoo.com/2013/01/full-spectrum-testing-with-angularjs-and-karma.html#testing-filters的中途测试代码示例中发现了这一点
以上是大佬教程为你收集整理的单元测试 – 如何在AngularJS单元测试中向DOM添加div?全部内容,希望文章能够帮你解决单元测试 – 如何在AngularJS单元测试中向DOM添加div?所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。