Hacktoberfest 2026: los issues que los mantenedores marcaron para octubre, abiertos y aptos para principiantes. Explorar issues de Hacktoberfest

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

Abierto
#526 0 comentarios 0 reacciones 0 asignados Ver en GitHub

Nadie ha tomado este issue todavía.

Evaluación

Dificultad
3/5
Tiempo estimado
1-2 días
Aptitud para principiantes
48/100
Tipo de issue
Error
Claridad
Bastante claro
Estado de actividad
Estancado
Stack tecnológico
javascript
Área
testing-qa

Línea de trabajo

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.

Escrito por el modelo de indexación a partir del texto del issue.

Descripción

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
Lenguaje dominante
JavaScript
Estrellas
1.4k
Forks
140
Merge medio
7 h 51 min
PR fusionados (30 d)
3

Preparar el entorno

Aún no hemos revisado los archivos de configuración de este proyecto. Empieza por su README y consulta nuestra guía para la primera contribución para los pasos generales.

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Más de testdouble/testdouble.js

Todos los issues de testdouble/testdouble.js

Issues similares

Más issues de JavaScript

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.