You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I am trying to run Jest tests on a code where the code itself (not the test) uses an if (variable instanceof ImageData) check. I included setupFiles: ["canvas"] in my jest.config.js file. When running tests, I get an error:
ReferenceError: ImageData is not defined
I know that this is because ImageData is a DOM construct and doesn't exist in the Node.js environment.
The canvas package includes its own implementation of ImageData and I'm wondering if that can be used as a polyfill. I don't get errors when using instanceof checks on HTMLCanvasElement and other DOM elements. Is my setup wrong, or is what I'm trying to do just not possible? And if it's not possible, is there a better way to check whether or not a variable is an ImageData object?
Your Environment
Version of node-canvas (output of npm list canvas or yarn list canvas):
Solution from this comment didn't work me as putImageData threw likely because of a mismatching class.
However turned out everything could be fixed simply adding ImageData from canvas package into global scope
Issue or Feature
I am trying to run Jest tests on a code where the code itself (not the test) uses an
if (variable instanceof ImageData)
check. I includedsetupFiles: ["canvas"]
in myjest.config.js
file. When running tests, I get an error:I know that this is because
ImageData
is a DOM construct and doesn't exist in the Node.js environment.The
canvas
package includes its own implementation ofImageData
and I'm wondering if that can be used as a polyfill. I don't get errors when usinginstanceof
checks onHTMLCanvasElement
and other DOM elements. Is my setup wrong, or is what I'm trying to do just not possible? And if it's not possible, is there a better way to check whether or not a variable is anImageData
object?Your Environment
npm list canvas
oryarn list canvas
):node v16.13.0 on Windows 10
The text was updated successfully, but these errors were encountered: