test: extend testRender to return spy on dispatch

This commit is contained in:
David Lechner
2022-03-10 02:00:14 -06:00
parent 41fc961661
commit b37209683b
5 changed files with 20 additions and 15 deletions
+6 -3
View File
@@ -132,19 +132,22 @@ export function lookup(obj: unknown, id: string): string | undefined {
*
* @param component The component to render.
* @param state Any state required by the component.
* @returns The render result.
* @returns The render result and a spy on the dispatch method.
*/
export const testRender = (
component: ReactElement,
state?: PreloadedState<RootState>,
): RenderResult => {
): [RenderResult, jest.SpyInstance<AnyAction, [action: AnyAction]>] => {
const store = createStore(rootReducer, state);
const dispatch = jest.spyOn(store, 'dispatch');
const i18n = new I18nManager({ locale: 'en' });
return render(
const result = render(
<Provider store={store}>
<I18nContext.Provider value={i18n}>{component}</I18nContext.Provider>
</Provider>,
);
return [result, dispatch];
};