diff --git a/src/shape/custom_shapes.js b/src/shape/custom_shapes.js index eee53018a3..31d34635ba 100644 --- a/src/shape/custom_shapes.js +++ b/src/shape/custom_shapes.js @@ -2174,6 +2174,17 @@ function customShapes(p5, fn) { * @returns {Number} The current Bézier order. */ fn.bezierOrder = function (order) { + if ( + !p5.disableFriendlyErrors && + order !== undefined && + order !== 2 && + order !== 3 + ) { + p5._friendlyError( + `bezierOrder() expects an order of 2 or 3, but received ${order}.`, + 'bezierOrder' + ); + } return this._renderer.bezierOrder(order); }; diff --git a/test/unit/core/vertex.js b/test/unit/core/vertex.js index f2403a4d08..00259c9694 100644 --- a/test/unit/core/vertex.js +++ b/test/unit/core/vertex.js @@ -31,6 +31,38 @@ suite('Vertex', function () { }); }); + suite('p5.prototype.bezierOrder', function () { + test('should be a function', function () { + assert.ok(myp5.bezierOrder); + assert.typeOf(myp5.bezierOrder,'function'); + }); + + test('should warn when the order is not 2 or 3', function () { + const _friendlyErrorStub = vi.spyOn(p5, '_friendlyError'); + myp5.bezierOrder(4); + expect(_friendlyErrorStub).toHaveBeenCalledTimes(1); + }); + + test('should not warn for an order of 2', function () { + const _friendlyErrorStub = vi.spyOn(p5, '_friendlyError'); + myp5.bezierOrder(2); + expect(_friendlyErrorStub).not.toHaveBeenCalled(); + }); + + test('should not warn for an order of 3', function () { + const _friendlyErrorStub = vi.spyOn(p5, '_friendlyError'); + myp5.bezierOrder(3); + expect(_friendlyErrorStub).not.toHaveBeenCalled(); + }); + + test('should not warn when reading the current order', function () { + const _friendlyErrorStub = vi.spyOn(p5, '_friendlyError'); + myp5.bezierOrder(); + expect(_friendlyErrorStub).not.toHaveBeenCalled(); + }); + + }); + suite('p5.prototype.splineVertex', function () { test('should be a function', function () { assert.ok(myp5.splineVertex);