Skip to content

Commit

Permalink
Refactor tests to use testHook and update to rtl
Browse files Browse the repository at this point in the history
  • Loading branch information
DoStini committed Apr 11, 2023
1 parent f782aa1 commit 83ec120
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 18 deletions.
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
/* eslint-disable react-hooks/rules-of-hooks */
import React from "react";
import { MemoryRouter, useLocation } from "react-router-dom";
import qs from "qs";

import { renderWithStoreAndTheme, TestComponent } from "../../../../test-utils";
import { testHookWithStoreAndTheme } from "../../../../test-utils";
import { act } from "react-dom/test-utils";
import useChipsFieldSearch from "./useChipsFieldSearch";
import { createTheme } from "@material-ui/core";
Expand All @@ -28,14 +27,7 @@ describe("useChipsFieldSearch", () => {
location = useLocation();
};


renderWithStoreAndTheme(
<MemoryRouter initialEntries={["/"]}>
<TestComponent callback={callback} />
</MemoryRouter>,
{ initialState, theme }
);

testHookWithStoreAndTheme(callback, initialState, theme, MemoryRouter);

expect(location).toHaveProperty("search", "");

Expand Down Expand Up @@ -80,13 +72,7 @@ describe("useChipsFieldSearch", () => {
location = useLocation();
};


renderWithStoreAndTheme(
<MemoryRouter initialEntries={["/"]}>
<TestComponent callback={callback} />
</MemoryRouter>,
{ initialState, theme }
);
testHookWithStoreAndTheme(callback, initialState, theme, MemoryRouter, { initialEntries: ["/"] });


expect(location).toHaveProperty("search", "");
Expand Down
14 changes: 13 additions & 1 deletion src/test-utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,13 +44,25 @@ export const TestComponent = ({ callback }) => {
};

export const testHook = (callback, Wrapper = React.Fragment, wrapperProps = {}) => {
mount(
defaultRender(
<Wrapper {...wrapperProps}>
<TestComponent callback={callback} />
</Wrapper>
);
};

export const testHookWithStoreAndTheme = (callback, initialState, theme, Wrapper = React.Fragment, wrapperProps = {}) => {
renderWithStoreAndTheme(
<Wrapper {...wrapperProps}>
<TestComponent callback={callback} />
</Wrapper>,
{
initialState,
theme,
}
);
};

const [queryDescriptionOf, , getDescriptionOf, , findDescriptionOf] = buildQueries(
function queryAllDescriptionsOf(container, element) {
return container.querySelectorAll(`#${element.getAttribute("aria-describedby")}`);
Expand Down

0 comments on commit 83ec120

Please sign in to comment.