From eb53247fd30a4a8c55bdb0b434b7e01f618d8612 Mon Sep 17 00:00:00 2001 From: Yusef Habib Fernandez Date: Wed, 18 Dec 2024 20:21:46 +0100 Subject: [PATCH] improve test --- .../reporting/ReportingDateRangeSelector.spec.ts | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/frontend/src/tests/lib/components/reporting/ReportingDateRangeSelector.spec.ts b/frontend/src/tests/lib/components/reporting/ReportingDateRangeSelector.spec.ts index eee9740281..8df0e956e8 100644 --- a/frontend/src/tests/lib/components/reporting/ReportingDateRangeSelector.spec.ts +++ b/frontend/src/tests/lib/components/reporting/ReportingDateRangeSelector.spec.ts @@ -24,6 +24,10 @@ describe("ReportingDateRangeSelector", () => { return { po, component }; }; + const getValueFromComponent = (component, propName: string) => { + return component.$$.ctx[component.$$.props[propName]]; + }; + it("should render the option provided as a prop", async () => { const { po } = renderComponent({ period: "last-year" }); @@ -64,12 +68,13 @@ describe("ReportingDateRangeSelector", () => { const { po, component } = renderComponent(); const allOptions = await po.getAllOptions(); - // Click the second option - await allOptions[1].click(); + let currentValue = getValueFromComponent(component, "period"); + expect(currentValue).toBe("all"); + await allOptions[1].click(); await tick(); - const currentValue = component.$$.ctx[component.$$.props["period"]]; + currentValue = getValueFromComponent(component, "period"); expect(currentValue).toBe("last-year"); }); });