I got an UIKit/index.js which exports other components out.
export { default as Button } from '../Button';
However, when testing any other components that import components from it
import { Button } from '../UIKit';
works fine in normal environment, but fails in Jest environment which Button is undefined when import.
Anyone knows how to fix it?
Hello!
Which version of Jest and npm are you using? I'm fairly confident that if you are using the latest versions of Jest and babel-jest, this shouldn't be an issue.
If your problem isn't resolved by that, please post more source code and your Jest configuration, ideally even a small repo that I can use to reproduce the issue. If this turns out to be an issue with Jest, I will reopen this issue :)
problem solved! I was previously using
const Button = require('../Button').default;
to avoid heist problem with import statement
When I changed to
import '../auto-mock-off';
import Button from '../Button';
and problem solved. Thx anyway
reference: https://github.com/rauschma/babel-on-node
Thanks for the solution, @AwesomeJerry. But it seems to be a very quirky one. I hope that underlying issue would be fixed soon and we would be able to get rid of this hack.
jest 0.9.3 (out next week) will contain jest.disableAutomock which will be hoisted above imports. It should resolve this issue.
I'm using jest 21.1.0 and this is still an issue:
export {default as Icon} from './icons/components/icon';
TypeError: Cannot redefine property: Icon
at Function.defineProperty (native)
Most helpful comment
I'm using
jest21.1.0and this is still an issue: