jest-canvas-mock
jest-canvas-mock copied to clipboard
Parameter 1 is not of type 'Path2D'
Hi, we are trying to replace the canvas
npm dependency with just your mock to speedup our ci infrastructure.
I've replaced the library and I'm getting the following error:
'CanvasRenderingContext2D': parameter 1 is not of type 'Path2D'
when something like this exists in my code:
ctx.stroke(new Path2D(line));
The problem seems caused by the fact that Path2D is available in my jest environment when running the test (Path2D doesn't probably need any special os-dependent treatment and is available in the jsdom) and you, correctly, don't mock if it is present: https://github.com/hustcc/jest-canvas-mock/blob/315d56b2dacf292f27fe84b690620957ddeadbdd/src/window.js#L47 The thing is that you check for a path2d being an instance of Your Path2D (and not the possible already available Path2D) https://github.com/hustcc/jest-canvas-mock/blob/315d56b2dacf292f27fe84b690620957ddeadbdd/src/classes/CanvasRenderingContext2D.js#L705-L710
Yes. This is quite the predicament. I will look at this today.
@jtenner a similar issue happens also with the DOMMatrix
as described here https://github.com/hustcc/jest-canvas-mock/issues/85
The canvas context getTransform
returns a DOMMatrix that is an instance of the internal implementation, not the one coming from the environment if present on window.