Skip to content

Commit

Permalink
Add reset
Browse files Browse the repository at this point in the history
  • Loading branch information
Tsubashi committed Aug 10, 2024
1 parent 487799b commit a35ee4f
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 0 deletions.
24 changes: 24 additions & 0 deletions __tests__/classes/CanvasRenderingContext2D.reset.js
Original file line number Diff line number Diff line change
@@ -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);
});
});
16 changes: 16 additions & 0 deletions src/classes/CanvasRenderingContext2D.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ const testFuncs = [
'fillRect',
'strokeRect',
'rect',
'reset',
'roundRect',
'resetTransform',
'translate',
Expand Down Expand Up @@ -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(
Expand Down

0 comments on commit a35ee4f

Please sign in to comment.