Hacktoberfest 2026:メンテナが10月に向けて印を付けた、オープンで初心者向けの issue。 Hacktoberfest の issue を見る

Functions that use Buffer will have TypeError in jest unit testing

オープン
#289 コメント 1 件 リアクション 0 件 担当者 0 名 GitHub で見る

まだ誰も着手していません。

評価

難易度
4/5
見積もり時間
3〜5日
初心者へのやさしさ
25/100
issue の種類
バグ
明瞭さ
説明が足りない
活発さ
停滞
技術スタック
javascript
領域
web-dev

調査の方向性

testEnvironment を jsdom に設定した Jest で、buffer ^6.0.3 と ArrayBuffer 入力を使用して、報告された関数を再現します。buffer-es6 の fromObject がその値をどのように処理するかを調べ、jsdom 環境と Node 環境を比較します。完了条件は、Buffer ベースの関数が jsdom で報告された TypeError をスローしなくなることです。

索引モデルが issue の本文から書いたものです。

説明

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?

主要言語
JavaScript
スター
1.9k
フォーク
260
PR マージ指標
30日以内にマージされた PR はありません

環境構築

このプロジェクトの環境構築ファイルはまだ確認していません。まず README を読み、一般的な手順ははじめてのコントリビューションガイドを参照してください。

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

feross/buffer のほかの issue

feross/buffer の issue をすべて見る

似ている issue

JavaScript の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。