PeculiarVentures / pvutils

pvutils is a set of common utility functions used in various Peculiar Ventures Javascript based projects.
Other
7 stars 13 forks source link

Don't use `instanceof ArrayBuffer`, it breaks in Jest #8

Open abonander opened 5 years ago

abonander commented 5 years ago

I'm trying to use asn1js but I'm getting an error from checkBufferParams in this lib due to the following problem which was previously fixed but has cropped up again in Node v11.15.0: https://github.com/nodejs/node/issues/20978#issuecomment-518900173

The problem is that Uint8Array.prototype.buffer instanceof ArrayBuffer always returns false when running code in Jest. It doesn't make any sense (even inspecting the value shows a class of ArrayBuffer) but it seems to be a bug in the current V8 version of Node.

The popular workaround seems to be to check the constructor name strings instead: https://github.com/Stuk/jszip/pull/598

YuryStrozhevsky commented 5 years ago

@abonander I do not want to make a workarounds on well-known bugs. Let's wait for the bug to be fixed in Node.

abonander commented 5 years ago

Node has announced that it's not their problem: https://github.com/nodejs/node/issues/20978#issuecomment-518953597

Jest has had an issue open since February: https://github.com/facebook/jest/issues/7780