YonatanKra / testing-canvas-with-jest

2 stars 0 forks source link

This step is no longer working properly. #1

Open LesniakM opened 1 year ago

LesniakM commented 1 year ago

Thank you for sharing your tutorial at https://yonatankra.com/how-to-test-html5-canvas-with-jest/ .

I tried to replicate everything, even copied all your files, but still I had error "ReferenceError: Path2D is not defined".

The reason for that is fact, that nowadays Jest by default uses node environment, not JSdom anymore.

To solve this problem, file package.json should be changed from:

"jest": {
    "setupFiles": ["jest-canvas-mock"]
  }

to:

"jest": {
    "testEnvironment": "jsdom",
    "setupFiles": ["jest-canvas-mock"]
  }

Moreover, installing jest-environment-jsdom might be needed. It can be done with: npm i jest-environment-jsdom --save-dev

DelphiCoder commented 9 months ago

As of December 2023, I can verify that the current commit still fails for the reasons stated by LesniakM.

His suggestions do fix the problem however.

Thank you to both Yonatan and Lesniak!!!