Skip to content

Commit 6cda130

Browse files
committed
fix(custom-chart-web): make useCustomChart test resolve under CI jest config
1 parent 3c81910 commit 6cda130

4 files changed

Lines changed: 13 additions & 11 deletions

File tree

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,4 @@
1-
const base = require("@mendix/pluggable-widgets-tools/test-config/jest.config.js");
2-
31
module.exports = {
4-
...base,
5-
testEnvironment: "@happy-dom/jest-environment",
6-
moduleNameMapper: {
7-
...base.moduleNameMapper,
8-
// Source uses baseUrl-relative imports (e.g. `from "src/controllers/..."`); map them to rootDir.
9-
"^src/(.*)$": "<rootDir>/$1"
10-
}
2+
...require("@mendix/pluggable-widgets-tools/test-config/jest.config.js"),
3+
testEnvironment: "@happy-dom/jest-environment"
114
};
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
// The chart controller imports plotly, which calls URL.createObjectURL at load time.
2+
// The pluggable-widgets-tools jest env (jsdom) doesn't implement it. Import this module
3+
// BEFORE anything that pulls in plotly to stub it.
4+
if (typeof window.URL.createObjectURL !== "function") {
5+
window.URL.createObjectURL = () => "";
6+
}
7+
8+
export {};

packages/pluggableWidgets/custom-chart-web/src/hooks/__tests__/useCustomChart.spec.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import "./stubObjectURL";
12
import { render, renderHook, screen, waitFor } from "@testing-library/react";
23
import { observer } from "mobx-react-lite";
34
import { createElement, ReactElement } from "react";

packages/pluggableWidgets/custom-chart-web/src/hooks/useCustomChart.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
import { Ref, RefCallback, useEffect } from "react";
2-
import { CustomChartControllerHost } from "src/controllers/CustomChartControllerHost";
3-
import { mergeRefs } from "src/utils/mergeRefs";
42
import { PlaygroundData } from "@mendix/shared-charts/main";
53
import { GateProvider } from "@mendix/widget-plugin-mobx-kit/GateProvider";
64
import { useConst } from "@mendix/widget-plugin-mobx-kit/react/useConst";
75
import { useSetup } from "@mendix/widget-plugin-mobx-kit/react/useSetup";
86
import { CustomChartContainerProps } from "../../typings/CustomChartProps";
7+
import { CustomChartControllerHost } from "../controllers/CustomChartControllerHost";
98
import { ControllerProps } from "../controllers/typings";
9+
import { mergeRefs } from "../utils/mergeRefs";
1010

1111
interface UseCustomChartReturn {
1212
playgroundData: PlaygroundData;

0 commit comments

Comments
 (0)