Functions that use Buffer will have TypeError in jest unit testing
- Dominant language
- JavaScript
- Stars
- 1.9k
- Forks
- 260
- PR merge metrics
- No merged PRs in 30d
Description
My function contains the following code :
```javascript
// data here is a Buffer obj example: data = Buffer('xxxx', 'base64')
var isBuffer = typeof data.readUInt32BE === 'function' && typeof data.slice === 'function';
if (isBuffer) {
this.highStart = data.readUInt32BE(0);
this.errorValue = data.readUInt32BE(4);
uncompressedLength = data.readUInt32BE(8);
data = data.slice(12);
} else {
var view = new DataView(data.buffer);
this.highStart = view.getUint32(0);
this.errorValue = view.getUint32(4);
uncompressedLength = view.getUint32(8);
data = data.subarray(12);
} // double inflate the actual trie data
```
I use `"buffer": "^6.0.3"`
I wrote a jest unit test for my function. It can pass when I run in the node environment, but if I set testEnvironment to jsdom, an error will appear as shown in the figure below.

Debug found that it seems that fromObject in buffer-es6 cannot handle this ArrayBuffer object. Is there any good way to circumvent this problem?

I don’t know if this is a jsdom problem or a Buffer problem?
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.