Skip to content

Commit

Permalink
fix(jest-canvas-mock): improve constructor for dom matrix (#118)
Browse files Browse the repository at this point in the history
  • Loading branch information
cibernox committed Feb 5, 2024
1 parent dc35dbc commit 39fe05b
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 1 deletion.
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

0 comments on commit 39fe05b

Please sign in to comment.