From a35ee4f97caed1d2a98cba7c60e4915836bd1693 Mon Sep 17 00:00:00 2001 From: Chandler Scott Date: Sat, 10 Aug 2024 13:45:36 -0600 Subject: [PATCH] Add reset --- .../classes/CanvasRenderingContext2D.reset.js | 24 +++++++++++++++++++ src/classes/CanvasRenderingContext2D.js | 16 +++++++++++++ 2 files changed, 40 insertions(+) create mode 100644 __tests__/classes/CanvasRenderingContext2D.reset.js diff --git a/__tests__/classes/CanvasRenderingContext2D.reset.js b/__tests__/classes/CanvasRenderingContext2D.reset.js new file mode 100644 index 0000000..79ab43d --- /dev/null +++ b/__tests__/classes/CanvasRenderingContext2D.reset.js @@ -0,0 +1,24 @@ +let canvas; +let ctx; + +beforeEach(() => { + canvas = document.createElement('canvas'); + ctx = canvas.getContext('2d'); + canvas.width = 400; + canvas.height = 300; +}); + +describe('reset', () => { + it('should be a function', () => { + expect(typeof ctx.reset).toBe('function'); + }); + + it('should be callable', () => { + ctx.rect(); + expect(ctx.reset).toHaveBeenCalled(); + }); + + it('should throw if any parameters are given', () => { + expect(() => ctx.rect(1)).toThrow(TypeError); + }); +}); diff --git a/src/classes/CanvasRenderingContext2D.js b/src/classes/CanvasRenderingContext2D.js index 51f10d6..95747d6 100644 --- a/src/classes/CanvasRenderingContext2D.js +++ b/src/classes/CanvasRenderingContext2D.js @@ -29,6 +29,7 @@ const testFuncs = [ 'fillRect', 'strokeRect', 'rect', + 'reset', 'roundRect', 'resetTransform', 'translate', @@ -1446,6 +1447,21 @@ export default class CanvasRenderingContext2D { this._path.push(event); } + reset() { + if (arguments.length > 0) { + throw new TypeError( + "Failed to execute 'reset' on '" + + this.constructor.name + + "': 0 arguments required, but " + + arguments.length + + ' present.' + ); + } + + const event = createCanvasEvent('reset') + this._events.push(event) + } + removeHitRegion(id) { if (arguments.length < 1) throw new TypeError(