Skip to content

Commit b97b8cf

Browse files
author
Lauren McCarthy
committed
forcing textWidth input to string closes #3851
1 parent 23b7b18 commit b97b8cf

File tree

2 files changed

+5
-10
lines changed

2 files changed

+5
-10
lines changed

src/typography/attributes.js

+3-2
Original file line numberDiff line numberDiff line change
@@ -215,9 +215,10 @@ p5.prototype.textStyle = function(theStyle) {
215215
*Letter P and p5.js are displayed with vertical lines at end. P is wide
216216
*
217217
*/
218-
p5.prototype.textWidth = function(theText) {
218+
p5.prototype.textWidth = function() {
219+
arguments[0] += '';
219220
p5._validateParameters('textWidth', arguments);
220-
if (theText.length === 0) {
221+
if (arguments[0].length === 0) {
221222
return 0;
222223
}
223224
return this._renderer.textWidth.apply(this._renderer, arguments);

test/unit/typography/attributes.js

+2-8
Original file line numberDiff line numberDiff line change
@@ -95,14 +95,8 @@ suite('Typography Attributes', function() {
9595
assert.isNumber(myp5.textWidth('p5.js'));
9696
});
9797
// Either should not throw error
98-
test('wrong param type at #0.', function() {
99-
assert.validationError(function() {
100-
myp5.textWidth(9);
101-
});
102-
});
103-
// Or should return NaN
104-
test.skip('should return NaN for wrong param.', function() {
105-
assert.isNumber(myp5.textWidth(100));
98+
test('should return a number for number input', function() {
99+
assert.isNumber(myp5.textWidth('p5.js'));
106100
});
107101
});
108102

0 commit comments

Comments
 (0)