From c11c31c4e528cd094827bbc6fd8797630323dfec Mon Sep 17 00:00:00 2001 From: Rakan Nimer Date: Wed, 2 Oct 2024 18:21:54 -0500 Subject: [PATCH] feat: add support for custom loader.js script location Fixes #730 --- .../src/hooks/useLoadGoogleCharts.ts | 4 +++- packages/react-google-charts/test/Bar.spec.tsx | 13 +++++-------- .../test/EventListening.spec.tsx | 15 +++++++-------- 3 files changed, 15 insertions(+), 17 deletions(-) diff --git a/packages/react-google-charts/src/hooks/useLoadGoogleCharts.ts b/packages/react-google-charts/src/hooks/useLoadGoogleCharts.ts index abb3da79..54658f31 100644 --- a/packages/react-google-charts/src/hooks/useLoadGoogleCharts.ts +++ b/packages/react-google-charts/src/hooks/useLoadGoogleCharts.ts @@ -66,7 +66,9 @@ export function useLoadGoogleCharts(props: ReactGoogleChartProps) { isLoading, error: scriptLoadingError, isSuccess, - } = useLoadScript("https://www.gstatic.com/charts/loader.js"); + } = useLoadScript( + props.chartLoaderScriptUrl || "https://www.gstatic.com/charts/loader.js", + ); useEffect(() => { if (!isSuccess) { diff --git a/packages/react-google-charts/test/Bar.spec.tsx b/packages/react-google-charts/test/Bar.spec.tsx index c966d827..d933dd18 100644 --- a/packages/react-google-charts/test/Bar.spec.tsx +++ b/packages/react-google-charts/test/Bar.spec.tsx @@ -1,5 +1,5 @@ import React from "react"; -import { render, cleanup, waitFor } from "@testing-library/react"; +import { render, cleanup, screen, waitFor } from "@testing-library/react"; import { Chart } from "../src"; describe("", () => { @@ -27,14 +27,11 @@ describe("", () => { />, ); - await waitFor(() => expect(getByTestId("1")).toContainHTML("svg"), { - timeout: 5000, + const root = await screen.findByTestId("1"); + await waitFor(() => { + expect(root).toBeVisible(); + expect(root.querySelector("svg")).toBeVisible(); }); - - const root = getByTestId("1"); - - expect(root).toBeVisible(); - expect(root.querySelector("svg")).toBeVisible(); }); }); }); diff --git a/packages/react-google-charts/test/EventListening.spec.tsx b/packages/react-google-charts/test/EventListening.spec.tsx index 3c4bd166..b09965e7 100644 --- a/packages/react-google-charts/test/EventListening.spec.tsx +++ b/packages/react-google-charts/test/EventListening.spec.tsx @@ -1,5 +1,5 @@ import React from "react"; -import { render, cleanup, waitFor, act } from "@testing-library/react"; +import { render, cleanup, waitFor, act, screen } from "@testing-library/react"; import "@testing-library/jest-dom"; import { Chart, @@ -106,8 +106,7 @@ describe("Event Listening", () => { rootProps: { "data-testid": "1" }, }; const { getByTestId, rerender } = render(); - - await waitFor(() => expect(getByTestId("1")), { timeout: 5_000 }); + await screen.findByTestId("1"); await waitFor(() => expect(eventCallback).toHaveBeenCalledWith("first rendering"), ); @@ -163,7 +162,7 @@ describe("Event Listening", () => { }; const { getByTestId, rerender, container } = render(); - await waitFor(() => expect(getByTestId("1")), { timeout: 5_000 }); + await screen.findByTestId("1"); await waitFor(() => expect(eventCallback).toHaveBeenCalledWith("first rendering"), ); @@ -233,8 +232,8 @@ describe("Event Listening", () => { , ); - await waitFor(() => expect(getByTestId("alphaChart")), { timeout: 5_000 }); - await waitFor(() => expect(getByTestId("betaChart")), { timeout: 5_000 }); + await screen.findByTestId("alphaChart"); + await screen.findByTestId("betaChart"); await waitFor(() => expect(eventCallback).toHaveBeenCalledWith("first rendering of alpha"), ); @@ -318,8 +317,8 @@ describe("Event Listening", () => { , ); - await waitFor(() => expect(getByTestId("alphaChart")), { timeout: 5_000 }); - await waitFor(() => expect(getByTestId("betaChart")), { timeout: 5_000 }); + await screen.findByTestId("alphaChart"); + await screen.findByTestId("betaChart"); await waitFor(() => expect(eventCallback).toHaveBeenCalledWith("first rendering of alpha"), );