import { spy } from 'sinon'; import { shallow } from 'enzyme'; // Utility method to asynchronously wait for component's willMount function to // complete. Requires the componentWillMount method *returns* its async promise // to wait for export const willMount = async unmountedComponent => { // Spy on the willmount method const lifecycleMethod = spy(unmountedComponent.type.prototype, 'componentWillMount'); const wrapper = shallow(unmountedComponent); // Wait for the return value of the spy (the promise returned in // componentWillMount) and then undo the mock await lifecycleMethod.returnValues[0]; lifecycleMethod.restore(); // Update component so async changes take place return wrapper.update(); };