Hacktoberfest 2026: những issue maintainer đã đánh dấu cho tháng Mười, đang mở và phù hợp người mới. Xem issue Hacktoberfest

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

Đang mở
#526 0 bình luận 0 reaction 0 người được giao Xem trên GitHub

Chưa có ai nhận issue này.

Đánh giá

Độ khó
3/5
Thời gian dự kiến
1-2 ngày
Mức phù hợp với người mới
48/100
Loại issue
Lỗi
Độ rõ ràng
Khá rõ ràng
Mức độ hoạt động
Đình trệ
Công nghệ
javascript
Lĩnh vực
testing-qa

Hướng nghiên cứu

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.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

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
Ngôn ngữ chính
JavaScript
Star
1.4k
Fork
140
Merge trung bình
7 giờ 51 phút
Pull request đã merge (30 ngày)
3

Chuẩn bị môi trường

Chúng tôi chưa kiểm tra các tệp thiết lập môi trường của dự án này. Hãy bắt đầu từ README và xem hướng dẫn đóng góp lần đầu của chúng tôi để biết các bước chung.

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của testdouble/testdouble.js

Tất cả issue của testdouble/testdouble.js

Issue tương tự

Thêm issue về JavaScript

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.