Hacktoberfest 2026: le issue che i maintainer hanno segnato per ottobre, aperte e adatte ai principianti. Sfoglia le issue Hacktoberfest

Functions that use Buffer will have TypeError in jest unit testing

Aperta
#289 1 commento 0 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
4/5
Tempo stimato
3-5 giorni
Idoneità per principianti
25/100
Tipo di issue
Bug
Chiarezza
Da chiarire
Stato di attività
Ferma
Stack tecnologico
javascript
Ambito
web-dev

Direzione di ricerca

Riproduci la funzione segnalata in Jest con testEnvironment impostato su jsdom, usando buffer ^6.0.3 e un input ArrayBuffer. Esamina come fromObject di buffer-es6 gestisce quel valore e confronta gli ambienti jsdom e Node; il lavoro è completato quando la funzione basata su Buffer non genera più il TypeError segnalato in jsdom.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

My function contains the following code :

// 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.

image

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

image

I don’t know if this is a jsdom problem or a Buffer problem?

Lingua principale
JavaScript
Stelle
1.9k
Fork
260
Metriche di merge delle PR
Nessuna PR unita negli ultimi 30g

Preparare l'ambiente

Non abbiamo ancora controllato i file di configurazione di questo progetto. Parti dal suo README e consulta la nostra guida al primo contributo per i passaggi generali.

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di feross/buffer

Tutte le issue di feross/buffer

Issue simili

Altre issue su JavaScript

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.