Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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);
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

test the throw message.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So, something like expect(() => ctx.reset(1)).toThrow(/Failed to execute 'reset' on/);?

});
});
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(
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is the information thrown standardized?

Copy link
Author

@Tsubashi Tsubashi Aug 12, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure what you mean by this. I tried to make it match the information used in the rect function.

"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