Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

td.imitate produces undefined for object keys of type Accessor #526

Open
13 tasks
italodirenzo93 opened this issue Feb 9, 2024 · 0 comments
Open
13 tasks

Comments

@italodirenzo93
Copy link

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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant