enzyme: React.Lazy always returning the Fallback value
Current behaviour
When writing a test to validate my component is rendered, I am only ever seeing the fallback value. I am unsure as to what I am doing incorrect or if this is an issue.
import React, { Suspense } from 'react';
const LazyComponent = React.lazy(() => import('./lazy-component-file'));
const ComponentWrapper = () => {
return (
<Suspense fallback='...'>
<LazyComponent />
</Suspense>
);
};
export default ComponentWrapper;
....
import { shallow } from 'enzyme';
import React from 'react';
import ComponentWrapper from './component-wrapper';
test('renders the suspense component', () => {
const wrapper = shallow(<ComponentWrapper />);
expect(wrapper.find('LazyComponent').length).toEqual(0); // Passes
});
test('renders the LazyComponent', () => {
const wrapper = shallow(<ComponentWrapper />, { suspenseFallback: false });
expect(wrapper.find('LazyComponent').length).toEqual(1); // Errors
});
Expected behaviour
I’ve tried exporting the LazyComponent
and doing:
expect(wrapper.find(LazyComponent).length).toEqual(1);
But my issue is flipped on its head and wrapper.find(LazyComponent).length
is always 1.
Your environment
API
- shallow
- mount
- render
Version
library | version |
---|---|
enzyme | 3.10.0 |
react | 16.8.6 |
react-dom | 16.8.6 |
react-test-renderer | 16.8.6 |
adapter (below) | 1.14.0 |
Adapter
- enzyme-adapter-react-16
- enzyme-adapter-react-16.3
- enzyme-adapter-react-16.2
- enzyme-adapter-react-16.1
- enzyme-adapter-react-15
- enzyme-adapter-react-15.4
- enzyme-adapter-react-14
- enzyme-adapter-react-13
- enzyme-adapter-react-helper
- others ( )
About this issue
- Original URL
- State: closed
- Created 5 years ago
- Reactions: 4
- Comments: 18 (9 by maintainers)
Commits related to this issue
- [Tests] add passing `suspenseFallback` tests See https://github.com/enzymejs/enzyme/issues/2200#issuecomment-671249671 — committed to enzymejs/enzyme by ljharb 4 years ago
- [Tests] add passing `suspenseFallback` tests See https://github.com/enzymejs/enzyme/issues/2200#issuecomment-671249671 — committed to enzymejs/enzyme by ljharb 4 years ago
- [Tests] add passing `suspenseFallback` tests See https://github.com/enzymejs/enzyme/issues/2200#issuecomment-671249671 — committed to enzymejs/enzyme by ljharb 4 years ago
- [Tests] add passing `suspenseFallback` tests See https://github.com/enzymejs/enzyme/issues/2200#issuecomment-671249671 — committed to enzymejs/enzyme by ljharb 4 years ago
- [Tests] add passing `suspenseFallback` tests See https://github.com/enzymejs/enzyme/issues/2200#issuecomment-671249671 — committed to enzymejs/enzyme by ljharb 4 years ago
- [Tests] add passing `suspenseFallback` tests See https://github.com/enzymejs/enzyme/issues/2200#issuecomment-671249671 — committed to enzymejs/enzyme by ljharb 4 years ago
- [Tests] add passing `suspenseFallback` tests See https://github.com/enzymejs/enzyme/issues/2200#issuecomment-671249671 — committed to web-developer77/react-enzyme by web-developer77 4 years ago
Yeah I was trying to use
wrapper.debug()
to see the output.The suspenseFallback option seems to not be making a difference to what is output.
I would have expected in the second example to see my
<LazyComponent />
in place of<lazy />
Still experiencing this issue.
@philearley does it work to you with
mount()
? to me it returns fallback as well asshallow()
does@liegeandlief no, the commit that closed the PR shows it’s not yet in enzyme-adapter-react-16. i’ll cut a release tomorrow.
Hi there, is there any update on the issue? Thanks.
Well, sadly I have to say that it’s still not working for me:
I’m using the latest version of every package: “enzyme”: “^3.11.0”, “enzyme-adapter-react-16”: “^1.15.6”,
Unfortunately this still isn’t working for me. My test is as follows:
My
PageSwitch
component is as follows:I have confirmed that it is reaching the
home
case in the switch block but the test does not seem to find theHome
component. TheHome
component is also memoized and has itsdisplayName
property set toHome
.Can you see anything I’m doing wrong here?
v1.15.3 of the adapter has been released.
I created #2328 to resolve this issue and make a note in PR, please read it.
@skyboyer when I tried to use mount I received warnings saying Mount was not supported.