Skip to content

Commit 05fac18

Browse files
committed
fix input validation for some Jest environments
Closes #62.
1 parent 197e8e2 commit 05fac18

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

index.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,8 @@ function pixelmatch(img1, img2, output, width, height, options) {
8181
}
8282

8383
function isPixelData(arr) {
84-
return arr instanceof Uint8Array || arr instanceof Uint8ClampedArray;
84+
// work around instanceof Uint8Array not working properly in some Jest environments
85+
return ArrayBuffer.isView(arr) && arr.constructor.BYTES_PER_ELEMENT === 1;
8586
}
8687

8788
// check if a pixel is likely a part of anti-aliasing;

0 commit comments

Comments
 (0)