diff --git a/__tests__/classes/DOMMatrix.js b/__tests__/classes/DOMMatrix.js index 062b4c0..ab060c2 100644 --- a/__tests__/classes/DOMMatrix.js +++ b/__tests__/classes/DOMMatrix.js @@ -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(); diff --git a/src/classes/DOMMatrix.js b/src/classes/DOMMatrix.js index cd4860e..62766ad 100644 --- a/src/classes/DOMMatrix.js +++ b/src/classes/DOMMatrix.js @@ -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]; diff --git a/types/index.d.ts b/types/index.d.ts index 687ab26..d5bba4d 100644 --- a/types/index.d.ts +++ b/types/index.d.ts @@ -1,4 +1,4 @@ -export function setupJestCanvasMock(window?: Window): void +export function setupJestCanvasMock(window?: Window): void; export interface CanvasRenderingContext2DEvent { /**