Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(jest-canvas-mock): improve constructor for dom matrix #118

Merged
merged 1 commit into from
Feb 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
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
6 changes: 6 additions & 0 deletions __tests__/classes/DOMMatrix.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,12 @@ describe('DOMMatrix class', () => {
expect(matrix.f).toBe(6);
});

it('should accept a DOMMatrix as parameter', () => {
const matrix = new DOMMatrix([1, 2, 3, 4, 5, 6]);
const matrix2 = new DOMMatrix(matrix);
expect(matrix2).toBeInstanceOf(DOMMatrix);
});

it('should be a 3d matrix if constructed without a parameter', () => {
const matrix = new DOMMatrix();
expect(matrix.is2D).toBeFalsy();
Expand Down
3 changes: 3 additions & 0 deletions src/classes/DOMMatrix.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,9 @@ export default class DOMMatrix {
m44 = 1.0;

constructor(transform) {
if (transform instanceof DOMMatrix) {
return transform;
}
if (transform && transform.length === 6) {
this.m11 = transform[0];
this.m12 = transform[1];
Expand Down
2 changes: 1 addition & 1 deletion types/index.d.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export function setupJestCanvasMock(window?: Window): void
export function setupJestCanvasMock(window?: Window): void;

export interface CanvasRenderingContext2DEvent {
/**
Expand Down