【发布时间】:2018-12-24 22:28:19
【问题描述】:
我有下一个功能:
fillText: function(text) {
this.node.innerHTML = text;
return {
width: this.node.clientWidth,
height: this.node.clientHeight
};
},
并对其进行单元测试:
it('Should return width and height of text node.', function() {
var sizeInPx = unit.fillText('ABCDEFGHIJKLMNOPQRSTUVWXYZ');
// width and height of text is different for different browsers
var widths = [408, 413, 421];
var heights = [13, 14];
expect(sizeInPx.width).to.be.oneOf(widths);
expect(sizeInPx.height).to.be.oneOf(heights);
});
此测试是非跨平台的,因为为不同的浏览器(Chrome、IE ...)指定了宽度和高度。现在这个测试在 MacOS 上失败了。
如何正确测试该功能?
【问题讨论】:
标签: javascript unit-testing testing cross-browser