Skip to content

Commit

Permalink
feat: add support for custom loader.js script location
Browse files Browse the repository at this point in the history
Fixes #730
  • Loading branch information
rakannimer committed Oct 2, 2024
1 parent 47adb78 commit c11c31c
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
13 changes: 5 additions & 8 deletions packages/react-google-charts/test/Bar.spec.tsx
Original file line number Diff line number Diff line change
@@ -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("<Chart />", () => {
Expand Down Expand Up @@ -27,14 +27,11 @@ describe("<Chart />", () => {
/>,
);

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();
});
});
});
15 changes: 7 additions & 8 deletions packages/react-google-charts/test/EventListening.spec.tsx
Original file line number Diff line number Diff line change
@@ -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,
Expand Down Expand Up @@ -106,8 +106,7 @@ describe("Event Listening", () => {
rootProps: { "data-testid": "1" },
};
const { getByTestId, rerender } = render(<Chart {...props} />);

await waitFor(() => expect(getByTestId("1")), { timeout: 5_000 });
await screen.findByTestId("1");
await waitFor(() =>
expect(eventCallback).toHaveBeenCalledWith("first rendering"),
);
Expand Down Expand Up @@ -163,7 +162,7 @@ describe("Event Listening", () => {
};
const { getByTestId, rerender, container } = render(<Chart {...props} />);

await waitFor(() => expect(getByTestId("1")), { timeout: 5_000 });
await screen.findByTestId("1");
await waitFor(() =>
expect(eventCallback).toHaveBeenCalledWith("first rendering"),
);
Expand Down Expand Up @@ -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"),
);
Expand Down Expand Up @@ -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"),
);
Expand Down

0 comments on commit c11c31c

Please sign in to comment.