-
Notifications
You must be signed in to change notification settings - Fork 12.6k
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
tslib: "TypeError: Cannot redefine property:" Bug Appears To Have Returned #43081
Comments
I'm having the same issue when mocking node's import * as path from 'path';
describe('test path', () => {
it('should mock path.resolve', () => {
const pathSpy = jest.spyOn(path, 'resolve').mockReturnValue('/');
path.resolve('my/unexisting/path');
expect(pathSpy).toHaveBeenCalledWith('my/unexisting/path');
});
}); Will throw: Changing the way that Typescript imports the module: import path from 'path' instead of import * as path from 'path' With this change the test passes but a
So consider importing just what you need (named imports) instead of importing all ( |
Hi, Any updates on the fix for this bug ? This is preventing us from upgrading tslib and typescript as we have 1000+ tests which would need to have a workaround with jest |
This is especially problematic because I find |
I got this everywhere in my code and look forward to when I can delete it // delete when resolved: https://github.com/microsoft/TypeScript/issues/43081
// eslint-disable-next-line @typescript-eslint/no-unsafe-return
jest.mock('foo', () => ({
__esModule: true,
...jest.requireActual('foo'),
})); |
It looks like the issue is that the |
Following discussion in the Design Meeting, we've decided not to take a fix for this as we would be inconsistent with esbuild, babel, et al. There are already workarounds for this, such as using |
Bug Report
Version 1.13.0 fixed the bug referenced here:
microsoft/tslib#102
But, in moving to either 2.0.0 or 2.1.0 - the bug is happening again.
🔎 Search Terms
tslib
TypeError: Cannot redefine property:
🕗 Version & Regression Information
This is fixed in 1.13.0 - but broke again in both version 2.0.0 and 2.1.0
💻 Code
internal/business functions/directories scrubbed from the following code snippet - but in case this makes it more clear
🙁 Actual behavior
We're forced to use relative paths when we use jest spyOn type functionality - instead of the aliased paths from tsconfig.
🙂 Expected behavior
We shouldn't have to update our paths to be relative paths.
The text was updated successfully, but these errors were encountered: