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

`td.imitate` produces `undefined` for object keys of type `Accessor`

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

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

評価

難易度
3/5
見積もり時間
1〜2日
初心者へのやさしさ
48/100
issue の種類
バグ
明瞭さ
おおむね明確
活発さ
停滞
技術スタック
javascript
領域
testing-qa

調査の方向性

Start at the td.imitate entry point and reproduce the class instance case under the Jest/SWC setup described in the issue. Add a regression test in the regression/src directory, using the Accessor and Function properties shown; done means the imitation no longer produces undefined for the Accessor property while preserving the method.

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

説明

Description

I'm working on a Next.js app that uses testdouble.js for mocking dependencies in tests. Our test environment uses Jest and runs under Babel. This issue revealed itself when attempting to alter our Jest config to use the Next.js Compiler (SWC) as described here.

The following code snippet run under Babel results in a passing test.

const myDependency = td.replace("../lib");

td.when(myDependency.doTheThing()).thenReturn(123);

expect(myFunction()).toBe("some result");

The same test run under SWC fails with the error

TypeError: myDependency.doTheThing() is not a function
Issue

Objects with Accessor properties result in undefined when run through td.imitate.

For example, given:

class Foo {
  get bar() {
    return 0;
  }

  baz() {
    return 1;
  }
}

The line:

const instance = new Foo();

produces an object with the type

{ bar: Accessor, baz: Function }

Running the class instance through td.imitate

const imitation = td.imitate(instance);

results in an object with the type

{ bar: undefined, baz: Function }
Environment
  • node -v output:
  • npm -v (or yarn --version) output:
  • npm ls testdouble (or yarn list testdouble) version:
Failing Test
  • Fork the repo
  • Add a failing test (probably to the `/regression/src' directory)
  • Submit a pull request for the failing test or link to your branch here
Example Repo
  • Create a minimal repository that reproduces the issue
  • Make sure that a fresh clone can run only npm it and observe the issue
  • Link to that repo here
Runkit Notebook
  • Create a Runkit notebook
  • Invoke var td = require('testdouble') at the top
  • Verify the behavior your issue is concerned with by clicking "Run"
  • Link to the Runkit here
主要言語
JavaScript
スター
1.4k
フォーク
140
平均マージ
7時間 51分
マージ済み PR(30日)
3

環境構築

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

はじめの一歩

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

testdouble/testdouble.js のほかの issue

testdouble/testdouble.js の issue をすべて見る

似ている issue

JavaScript の issue をもっと見る

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

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