I have a component with this kind of setup
const ChestWithToys = ({toyBoxId, handleTidyToys})=> {
/* do stuff with toys */
useEffect(() => () => handleTidyToys(), [toyBoxId])
}
And this is in my test with enzyme and act (from react-dom/test-utils)
it('tidies toys on unmount', () => {
let handleTidyToys = sinon.stub();
let wrapper = shallow(<ChestWithToys toyBoxId={1} handleTidyToys={handleTidyToys} />);
expect(handleTidyToys).to.have.callCount(0);
act(() => {
wrapper.unmount();
});
expect(handleTidyToys).to.have.callCount(1);
});
The component functions as expected. However in the test handleTidyToys is never called. What gives? I can't find a better example where unmounting takes place, but from what I can see that should trigger my cleanup callback.
If I replace the unmount with setProps and change the queryId, it still doesn't trigger.
Is enzyme incompatible, or have I made some other mistake?
edit: I've just dropped a load of console.logs into the useEffect, and around it and it's not running at all.