import React from 'react' ; import { mount , ReactWrapper } from 'enzyme' ; import { act } from 'react-dom/test-utils' ; import { mountWithIntl } from './mount_with_i18n' ; /**
 * This helper is intended for components that have async effects
 * (e.g. http fetches) on mount. It mostly adds act/update boilerplate
 * that's needed for the wrapper to play nice with Enzyme/Jest
 *
 * Example usage:
 *
 * const wrapper = mountAsync(<Component />);
 */ interface Options { i18n ? : boolean ; } export const mountAsync = async ( children , options ) : Promise < ReactWrapper > => { let wrapper ; await act ( async ( ) => { wrapper = options . i18n ? mountWithIntl ( children ) : mount ( children ) ; } ) ; if ( wrapper ) { wrapper . update ( ) ; return wrapper ; } else { throw new Error ( 'Could not mount wrapper' ) ; } } ;