Files upload testing in Enzyme Files upload testing in Enzyme reactjs reactjs

Files upload testing in Enzyme


You'll need to provide a mocked event object, something like:

wrapper.find('FileInput').simulate('change', {  target: {     files: [       'dummyValue.something'     ]     }});

Your component its making a lot of work inside, its like a huge side effect (it defines two callbacks with logic nailed). It's going to be difficult, but I suppose you'll need to mock FileReader as well using two spies, one reacting to the readAsDataURL calling the onload and another one calling the onerror.

Then you can check if your callbacks are doing what is supposed to.

Hope it helps!