Skip to content

Commit b62920c

Browse files
committed
[fix] step test, add children component
1 parent ebeb251 commit b62920c

File tree

1 file changed

+9
-14
lines changed

1 file changed

+9
-14
lines changed

src/scripts/components/Step/Step.spec.js

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@ import { StepContext } from "../../context/StepContext";
44
import '@testing-library/jest-dom';
55
import Step from "./Step";
66
import { MemoryRouter } from "react-router";
7+
import ContactDetails from "../ContactDetails/ContactDetails";
8+
import InvestmentPlans from "../InvestmentPlans/InvestmentPlans";
9+
import InvestmentPreferences from "../InvestmentPreferences/InvestmentPreferences";
710

811
describe("Step test", () => {
912

@@ -12,45 +15,37 @@ describe("Step test", () => {
1215
* @param {Context} step
1316
* @returns The render of the Step component with the usage of the context value
1417
*/
15-
function renderStep(step) {
16-
let path = "/";
17-
if (step === 2) {
18-
path = "/step2";
19-
} else if (step === 3) {
20-
path = "/step3";
21-
}
18+
function renderStep(step, component) {
2219

2320
return render(
2421
<StepContext.Provider value={[step]}>
25-
<MemoryRouter initialEntries={[path]}>
26-
<Step />
27-
</MemoryRouter>
22+
<Step >{component}</Step>
2823
</StepContext.Provider>
2924
);
3025
}
3126

3227
afterEach(cleanup);
3328

3429
it("should render the step", () => {
35-
renderStep(1);
30+
renderStep(1, <ContactDetails />);
3631

3732
expect(screen.getByTestId("step")).toBeInTheDocument();
3833
});
3934

4035
it("should render the contact component in the first step", () => {
41-
renderStep(1);
36+
renderStep(1, <ContactDetails />);
4237

4338
expect(screen.getByTestId("contact")).toBeInTheDocument();
4439
});
4540

4641
it("should render the investment plans component in the second step", () => {
47-
renderStep(2);
42+
renderStep(2, <InvestmentPlans />);
4843

4944
expect(screen.getByTestId("investment-plans")).toBeInTheDocument();
5045
});
5146

5247
it("should render the investment preferences component in the third step", () => {
53-
renderStep(3);
48+
renderStep(3, <InvestmentPreferences />);
5449

5550
expect(screen.getByTestId("investment-preferences")).toBeInTheDocument();
5651
});

0 commit comments

Comments
 (0)