-
-
Notifications
You must be signed in to change notification settings - Fork 14
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
jest failed when testing a component that use #15
Comments
Unfortunately, I'm not quite sure about what's happening here. However, I suspect that the issue is related to your bundler or testing environment configuration rather than the library itself. |
in create-react-app if you try to import this library in jest, then jest returns this object: it would seem that if jest doesn't recognize file extension, then it defauls to just returning bundle file name (it may be convenient if you are for example importing images or something that is not shown during unit tests) if you were to change generated common js bundle name from out of all imported libraries in my project this one seems to be the only one which has |
@arturwojtas Thank you for the detailed explanation! I'll look into this soon. |
If you need workaround to make your jest tests to work, then something like this works for me: const defaultElement = "div";
export const mockBox = React.forwardRef((props, ref) => {
const Element = props.as || defaultElement;
return <Element ref={ref} {...props} as={undefined} />;
});
jest.mock("react-polymorphic-box", () => ({ Box: mockBox })); |
This should be resolved by v2.0.6. Thanks to all of you for reporting again! |
Description
I've got an error during jest test process when I test a component that import a component who use Box.
The problem is that this component is located in our private component library and the issue only happened in this particular case. If I directly test the component directly in the library there is no problem at all.
Here is my architecture :
Here is the error :
The react render works, the problem came only when using jest
Workaround
Reproduction
To reproduce it you have to import a component from a library that use polymorphic.
Possible issue location
Maybe the issue is the bundle generated
Environment
System:
Binaries:
Browsers:
Libs:
react-scripts: 3.4.1
jest: 24.9.0
@testing-library/react: 10.4.4
I can't create a codesandbox to reproduce this issue but if you have any question, please ask :)
The text was updated successfully, but these errors were encountered: