Testing with React's Jest and Enzyme when async componentDidMount
Solution:
1: use the async/await syntax.
2: Use mount (no shallow).
3: await async componentLifecycle.
For ex:
test(' ',async () => {
const wrapper = mount(
<Foo />
);
await wrapper.instance().componentDidMount();
})
Something like this should work for you:-
describe('...', () => {
test('...', async () => {
const wrapper = await mount(<Foo/>);
expect(wrapper.instance().bar).toBe(100);
});
});
Try this:
it('should do something', async function() {
const wrapper = shallow(<Foo />);
await wrapper.instance().componentDidMount();
app.update();
expect(wrapper.instance().bar).toBe(100);
});