I have next function:
fillText: function(text) {
this.node.innerHTML = text;
return {
width: this.node.clientWidth,
height: this.node.clientHeight
};
},
And unit test for it:
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);
});
This test is non cross-platform, because widths and heights specified for different browsers (Chrome, IE ...). And at now this test fails on MacOS.
How to test that function right?
Aucun commentaire:
Enregistrer un commentaire