score:0

Accepted answer

Found a rather simple solution. Use Async/Await:

test('doSomething should trigger ChildComponentB to pop up', async() => {
  const wrapper = shallow(
    <MyComponent
    ...
    />,
  ).dive();

  await wrapper.instane().doSomething(params);

  const childComponentB = wrapper.find('ChildComponentB');
  expect(childComponentB).toHaveLength(1);
});

score:-1

    it('check List component for column list', async () => {
    #ur code for re-render stuff
    await new Promise(resolve => setTimeout(resolve, 0)); // wait for response

    # this will sync ur wrapper with latest tree change
    wrapper = wrapper.update();  
});

score:0

You can try to manually update the component to get the latest state:

  wrapper.instance().doSomething(params); // assume params is defined
  wrapper.update(); 
  const childComponentB = container.find('ChildComponentB');
  expect(childComponentB).toHaveLength(1);

More info: https://airbnb.io/enzyme/docs/api/ShallowWrapper/update.html

score:0

Not sure if this will work or not but lets try updating the doSomething function as.

doSomething = (params) => {
  this.setState({ 
    renderChildA: false,
    renderChildB: true,
  },() => this.renderChildren());
}

score:0

Just add async and await

test('describe your test', async() => { // add async here
  const wrapper = shallow(
    <MyComponent
      ...
    />,
  ).dive();

  await wrapper.instane().doSomething(params); // add wait here

  const childComponentB = wrapper.find('ChildComponentB');
  expect(childComponentB).toHaveLength(1)
});

Related Query

More Query from same tag