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
TypeError: Cannot set property logger of #<Object> which has only a getter #8363
Comments
Hey @jmikulka! We really appreciate you taking the time to report an issue. The collaborators If you need any help, or just have general Babel or JavaScript questions, we have a vibrant Slack |
Based on a slack discussion https://babeljs.slack.com/archives/C0DFJT81H/p1533733732000482 I've found a solution. In
with
However, by mocking |
I'm getting the same error after upgrading to babel 7. In addition to this getter error, I'm getting an error that seems to be common when minified files are not properly separated by semicolons,
|
Any update on this issue? |
Encountered the same issue in my tests. I think, mocking the dependency is the only right approach, cause patching exported object is pretty unsafe and can lead to unexpected behaviour. So from that point of view it's good that babel 7 started enforcing this. jest.mock("./deps", () => ({
...jest.requireActual("./deps"),
logger: jest.fn()
}));
test("test something", () => {
const deps = require("./deps");
// do something
expect(deps.logger).toHaveBeenCalled();
}); That's how I solved it in my tests :) |
Yah that is a good solution. I'm closing this issue because it's not a bug; the specification mandates that esmodules may not be mutated from the outside. |
v7 Regression
Potential Commit/PR that introduced the regression
N/A
Describe the regression
Running jest tests with the babel-preset-env@6 pass:
After upgrade to @babel/preset-env@7, the tests fail:
Input Code
Clone https://github.com/jmikulka/babel_preset_env_regression and run:
Babel Configuration (.babelrc, package.json, cli command)
Expected behavior/code
The tests with the new preset should not fail.
Environment
babel-jest
]The text was updated successfully, but these errors were encountered: