-
-
Notifications
You must be signed in to change notification settings - Fork 79
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
Can't use jest spies for functions in same file #610
Comments
I have same pb too. It works perfectly with ts-jest. |
I'll take a look soon |
It is because SWC doesn't add SWC : "use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.someFunc = exports.addOne = void 0;
const addOne = (x)=>`${x + 1}`
;
exports.addOne = addOne;
const someFunc = (x)=>`The answer is : ${addOne(x)}` TypeScript: "use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.someFunc = exports.addOne = void 0;
const addOne = (x) => `${x + 1}`;
exports.addOne = addOne;
const someFunc = (x) => `The answer is : ${(0, exports.addOne)(x)}`;
exports.someFunc = someFunc; |
/cc @kdy1 |
Seems like swc-project/swc#2549 ? |
Yes, thanks! |
I haven't tried this lib again since this issue, did #2569 fix this, or is this still expected at the moment? |
This still seems to be an error. @Brooooooklyn any idea when this will be addressed, or if ever? |
This is not an error/bug. That something else makes something possible does not make it right. SWC is the one doing the right thing here, as the resolved ESM exports are supposed to be immutable. Just for reference, the output for CommonJS has changed a bit to be closer to actual ESM semantics, which should clarify what is going on (it's using getters): "use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
function _export(target, all) {
for(var name in all)Object.defineProperty(target, name, {
enumerable: true,
get: all[name]
});
}
_export(exports, {
addOne: function() {
return addOne;
},
someFunc: function() {
return someFunc;
}
});
const addOne = (x)=>`${x + 1}`;
const someFunc = (x)=>`The answer is : ${addOne(x)}`; If you actually intend for |
Thank you! See swc-project/swc#7435 |
If I have a file that contains
And I want to test the two functions separately and therefore mock
addOne
:with
ts-jest
, this code snippet provided works. With@swc-node/jest
, it seems any jest spies from the same file cannot be spied on, and if they are, result in the error:expect(jest.fn()).toHaveBeenCalledWith(...expected) Expected: 1 Number of calls: 0
Note that I have tried the exact same scenario but exporting them as actual functions (i.e.
export function someFunc(x: number): string {
), but still run into the same problem.The text was updated successfully, but these errors were encountered: