diff --git a/src/app/shared/utils/testing/renderFromAlien.tsx b/src/app/shared/utils/testing/renderFromAlien.tsx new file mode 100644 index 00000000..5fb8f7b9 --- /dev/null +++ b/src/app/shared/utils/testing/renderFromAlien.tsx @@ -0,0 +1,38 @@ +import { RenderResult } from '@testing-library/react'; +import { renderHook, RenderHookResult } from '@testing-library/react-hooks'; +import { ReactElement } from 'react'; +import { act } from 'react-test-renderer'; +import { Store } from 'redux'; + +import alien, { AlienStore } from '~/store/config/alienStore/alien'; +import { withProvider, WrapperType } from '~/store/config/alienStore/helpers/withProvider'; +import { State } from '~/store/State'; + +const store = alien(); + +const wrapper = withProvider(store); + +export interface RenderFromAlienResult extends RenderHookResult { + store: AlienStore; + wrapper: WrapperType; +} + +export default async function renderWithAlien( + Ui: () => ReactElement, +): Promise { + let hookResult = {} as RenderHookResult; + + await act(async () => { + hookResult = renderHook(Ui, { wrapper }); + }); + + return { + ...hookResult, + // adding `store` to the returned utilities to allow us + // to reference it in our tests (just try to avoid using + // this to test implementation details). + store, + // Redux Provider with store already given from alien. + wrapper, + }; +}