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 wrote this little blurb to automatically detect a JSDOM Image in the toMatchImageSnapshot snapshot and think it would be useful if it was unstreamed. Here is my setupFilesAfterEnv file:
/** * Takes a JSDOM image and returns a Node.js buffer to use * with jest-image-snapshot. */functionimageToBuffer(image: HTMLImageElement): Buffer{constcanvas=document.createElement('canvas');canvas.width=image.width;canvas.height=image.height;constctx=canvas.getContext('2d');ctx.drawImage(image,0,0);constbase64=canvas.toDataURL().split(',')[1];returnBuffer.from(base64,'base64');}expect.extend({toMatchImageSnapshot: function(received,options){// If these checks pass, assume we're in a JSDOM environment with the 'canvas' package.if(received&&received.constructor&&received.constructor.name==='HTMLImageElement'){received=imageToBuffer(received);}returntoMatchImageSnapshot.call(this,received,options);}});
Best,
The text was updated successfully, but these errors were encountered:
Hello! Thanks for open sourcing
jest-image-snapshot
and working with the community on it!I'm trying to use this for
Image
from jsdom, which you can automatically set up in Jest https://jestjs.io/docs/configuration#testenvironment-string and with the peerdepcanvas
. https://github.com/jsdom/jsdom#canvas-supportI wrote this little blurb to automatically detect a JSDOM Image in the
toMatchImageSnapshot
snapshot and think it would be useful if it was unstreamed. Here is mysetupFilesAfterEnv
file:Best,
The text was updated successfully, but these errors were encountered: