我正在编写一个单元测试,使用了getComputedTextLength()方法,在除IE浏览器(我使用的是IE10)以外的所有浏览器中都通过了测试。
有什么建议吗?
这是我得到的错误信息:Unexpected call to method or property access.
我正在编写一个单元测试,使用了getComputedTextLength()方法,在除IE浏览器(我使用的是IE10)以外的所有浏览器中都通过了测试。
有什么建议吗?
这是我得到的错误信息:Unexpected call to method or property access.
当元素不在可见的DOM中时,会出现这种情况。您可以事先进行检查,避免使用try/catch。
if(!document.body.contains(self.node())) return;
var a;
try{
a=textElement_.getComputedTextLength();
}catch(e){
a=textElement_.childNodes[0].length*8; //I used 8 as a width, but you should experiment
}