wobsoriano / vitest-canvas-mock

🌗 A module used to mock canvas in Vitest.
MIT License
54 stars 9 forks source link

TypeError: Cannot read property 'prototype' of undefined #8

Closed ad1992 closed 1 month ago

ad1992 commented 1 year ago

Hi @wobsoriano thanks for this package!

I am trying to migrate CRA to Vite in Excalidraw and running into issues when migrating tests. We are using jest-canvas-mock and thats how I came across this library when migrating to Vite. However I am getting 👇🏻 error

Screenshot 2023-06-22 at 12 44 02 PM

In addition when I disable the threads as suggested in the Readme, the tests just hangs and I have to manually terminate.

Could you tell me how can I fix it ?

ad1992 commented 1 year ago

On further debugging, this is where its thrown from in jest-canvas-mock in prototype.js. The win object doesn't have HTMLCanvasElement hence the error

Screenshot 2023-06-22 at 3 58 16 PM

ad1992 commented 1 year ago

There is an issue for the same opened in jest-canvas-mock

jenaicprb commented 1 year ago

On further debugging, this is where its thrown from in jest-canvas-mock in prototype.js. The win object doesn't have HTMLCanvasElement hence the error

Screenshot 2023-06-22 at 3 58 16 PM

Hi @ad1992 ,

Would you have a gist with the exact steps you followed? Seems you've patched the code in jest-canvas-mock, then use selective version resolutions?

jenaicprb commented 1 year ago

For those who need it:

With Yarn, in your package.json

"resolutions": {
    "vitest-canvas-mock/jest-canvas-mock": "2.4.0"
}

Thanks @ad1992

ardeshiir commented 1 year ago

I have the same problem I tried the solution above by @jenaicprb , but I use npm so my alternative to yarn's "resolution" was this: "overrides": { "vitest-canvas-mock": { "jest-canvas-mock": "2.4.0" } } but I still get the same error

wobsoriano commented 1 year ago

Latest version uses jest-canvas-mock@2.4.0, still getting the error?

ad1992 commented 1 year ago

Yes the patch version of Vite works well and resolutions field isn't needed anymore, Thanks @wobsoriano

Also the issue seems to be fixed in jest-canvas-mock@2.5.2 reference - https://github.com/hustcc/jest-canvas-mock/pull/116 , can you release a patch version for vitest-canvas-mock ?

wobsoriano commented 1 year ago

@ad1992 updated to use jest-canvas-mock@2.5.2! Let me know if that still works.

ad1992 commented 1 month ago

@ad1992 updated to use jest-canvas-mock@2.5.2! Let me know if that still works.

A little late here, but yes everything works well so I am closing this.

Thanks @wobsoriano ✨