@forge/react

11.18.0-next.011.18.0-next.1
out/router/utils/test-utils.js
+out/router/utils/test-utils.jsNew file
+23
Index: package/out/router/utils/test-utils.js
===================================================================
--- package/out/router/utils/test-utils.js
+++ package/out/router/utils/test-utils.js
@@ -0,0 +1,23 @@
+"use strict";
+Object.defineProperty(exports, "__esModule", { value: true });
+exports.createMockHistory = void 0;
+const history_1 = require("history");
+/**
+ * Creates a mock history object that emulates the v4 history API.
+ * The bridge returns a v4-style history object at runtime where `listen`
+ * calls back with `location` directly, but `createMemoryHistory` from
+ * the installed history v5 package passes `{ action, location }`.
+ * This wrapper adapts the v5 listener to behave like v4.
+ */
+const createMockHistory = (initialPath = '/') => {
+    const history = (0, history_1.createMemoryHistory)({ initialEntries: [initialPath] });
+    const originalListen = history.listen.bind(history);
+    history.listen = (callback) => {
+        return originalListen(({ location }) => callback(location));
+    };
+    jest.spyOn(history, 'push');
+    jest.spyOn(history, 'replace');
+    jest.spyOn(history, 'go');
+    return history;
+};
+exports.createMockHistory = createMockHistory;