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

Parameter 1 is not of type 'Path2D' #86

Open
markov00 opened this issue Aug 27, 2021 · 2 comments
Open

Parameter 1 is not of type 'Path2D' #86

markov00 opened this issue Aug 27, 2021 · 2 comments

Comments

@markov00
Copy link

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:

if (!win.Path2D) win.Path2D = Path2D;

The thing is that you check for a path2d being an instance of Your Path2D (and not the possible already available Path2D)
if (arguments.length === 2 && !(path instanceof Path2D))
throw new TypeError(
"Failed to execute 'drawFocusIfNeeded' on '" +
this.constructor.name +
"': parameter 1 is not of type 'Path2D'."
);

@jtenner
Copy link
Collaborator

jtenner commented Aug 27, 2021

Yes. This is quite the predicament. I will look at this today.

@markov00
Copy link
Author

markov00 commented Sep 1, 2021

@jtenner a similar issue happens also with the DOMMatrix as described here #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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants