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
Failing Test
Example Repo
Runkit Notebook
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.
The same test run under SWC fails with the error
Issue
Objects with
Accessorproperties result inundefinedwhen run throughtd.imitate.For example, given:
The line:
produces an object with the type
Running the class instance through
td.imitateresults in an object with the type
Environment
node -voutput:npm -v(oryarn --version) output:npm ls testdouble(oryarn list testdouble) version:Failing Test
Example Repo
npm itand observe the issueRunkit Notebook
var td = require('testdouble')at the top