-
-
Notifications
You must be signed in to change notification settings - Fork 2k
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
Stateless functional components support #319
Comments
Can you confirm which version of React you're using? The error message implies 0.13, which doesn't support SFCs. |
Sorry: |
@montogeek did you find a solution for mounting stateless functional components, because they don't work for me using Enzyme 2.2.0 together with React 0.14.1 (nor does it work with React 15.0.1). I now use the workaround I found at #45 (comment) but this defeats the purpose of using stateless components... |
@nvdbleek No, I thought it was a problem with React 0.14.1, never fixed it. Have you tried returning As a note, React 15 is fully supported according to @ljharb https://gitter.im/airbnb/enzyme?at=571aa7269689a5440f7ab469 |
@montogeek I believe the issue with your original snippet is that you're returning a string as the default case. This isn't supported, even by React I've verified that the current it('Should not render if a name is not provided', () => {
const Icon = ({ name }) => {
switch (name) {
case 'airport': return <div>{name}</div>;
case 'place': return <h2>{name}</h2>;
default: return null;
}
};
shallow(<Icon />);
}); If you return a string from a stateless component with React 15 you get a more helpful error when running your test:
|
I hope that this is the problem, but I don't think that we return a string in the stateless components where we have the problem, but I'll check. |
@nvdbleek if you are having a separate issue, I'd appreciate if you could share the code snippet causing your error! |
@aweary I will try to create a small test case, the problem happens in some big components, and as I saw this issue I didn't took the time to create a small test-case yet. |
@aweary Sorry for providing incorrect information. The problem isn't caused by enzyme, but by the auto-mocking of jest. An auto mocked Stateless Functional Component returns |
@nvdbleek if you have a reproducable case showing that SFCs return |
@aweary it isn't a 'bug' in jest in my opinion. All auto-mocked functions return |
I wouldn't say it's a bug, I'm just curious if jest could recognize when it's mocking a React component and handle that accordingly, or if there would be a way to declare a custom global return value for all (or a set of)mock'd functions. I'm not super familiar with jest though, so IDK what that would involve. Anyways, if there's no reproducable case of enzyme failing with SFCs, this issue should probably be closed @ljharb |
I'm asking the question to cpojer on th Discord jest channel. If I get an answer, I'll update this github issue |
We just merged #394 which added lots of tests for SFCs. Since there doesn't seem to be an actual issue here I'm going to close this out |
Hi!
I am trying to test the following SFC:
With the following test:
Getting the following error:
The text was updated successfully, but these errors were encountered: