var result = categories.find(ct => ct.id() === categoryId);
when I run jest, I got a error what - TypeError: Object #
I know that I should import core-js to solve that error but he fact that I should import core-js every time using jest bothers me a lot.
What I want is to load core-js automatically when I run jest.
Is loading core-js automatically implemented already? or should I fork it and pull request.
Please let me know :)
You can load polyfills into the environment by using config.setupEnvScriptFile and then require.requireActual (I think to make sure it's not mocked) from there.
See what we do in jstransform: https://github.com/facebook/jstransform/blob/master/package.json#L42 & https://github.com/facebook/jstransform/blob/master/jestEnvironment.js
@zpao thank you a lot
For anyone that lands on this these days, the modern day fix is have a setupFiles setting in your package.json:
"setupFiles": [
"<rootDir>/internal/tests/browserMocks.js"
],
In the browserMocks.js file include this require statement at the top:
require('core-js');
For anyone who's too lazy to create a browserMocks.js file, you can set core-js directly in your package.json:
"setupFiles": [
"<rootDir>/node_modules/core-js"
]
If you'd like to be even lazier you can use the name only, too:
"setupFiles": ["core-js"]
Most helpful comment
For anyone that lands on this these days, the modern day fix is have a
setupFilessetting in yourpackage.json:In the
browserMocks.jsfile include thisrequirestatement at the top: