@trackunit/react-vite-test-setup 0.0.149-alpha-f60e0f7c192.0 → 0.0.151
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/index.cjs.js +24 -0
- package/index.esm.js +24 -0
- package/package.json +1 -1
- package/migrations/entry.js.map +0 -1
package/index.cjs.js
CHANGED
|
@@ -157,6 +157,23 @@ const ensureJestGlobalAlias = () => {
|
|
|
157
157
|
globalAny.jest = vitest.vi;
|
|
158
158
|
}
|
|
159
159
|
};
|
|
160
|
+
/**
|
|
161
|
+
* `@googlemaps/jest-mocks`' initialize() does not register TrafficLayer on
|
|
162
|
+
* `google.maps` (it only exists behind its importLibrary mock), so tests get
|
|
163
|
+
* a minimal fake with the setMap/getMap surface the Google adapter uses.
|
|
164
|
+
* Module-scoped so its prototype stays stable across tests for spying.
|
|
165
|
+
*/
|
|
166
|
+
class TrafficLayerFake {
|
|
167
|
+
constructor() {
|
|
168
|
+
this.attachedMap = null;
|
|
169
|
+
}
|
|
170
|
+
setMap(map) {
|
|
171
|
+
this.attachedMap = map;
|
|
172
|
+
}
|
|
173
|
+
getMap() {
|
|
174
|
+
return this.attachedMap;
|
|
175
|
+
}
|
|
176
|
+
}
|
|
160
177
|
/**
|
|
161
178
|
* Sets up mocks for Google Maps API and @vis.gl/react-google-maps components
|
|
162
179
|
* in testing environments.
|
|
@@ -263,6 +280,7 @@ const setupGoogleMaps = () => {
|
|
|
263
280
|
}),
|
|
264
281
|
},
|
|
265
282
|
};
|
|
283
|
+
Object.assign(global.window.google.maps, { TrafficLayer: TrafficLayerFake });
|
|
266
284
|
});
|
|
267
285
|
};
|
|
268
286
|
|
|
@@ -825,6 +843,12 @@ vitest.afterEach(async () => {
|
|
|
825
843
|
vitest.vi.clearAllMocks();
|
|
826
844
|
react.cleanup();
|
|
827
845
|
await flushPromisesInAct();
|
|
846
|
+
// jsdom keeps window.history across tests in a file. Reset after cleanup() so any
|
|
847
|
+
// router history has been destroyed and this is not seen as a navigation. Some specs
|
|
848
|
+
// replace window.history with a stub that has no replaceState.
|
|
849
|
+
if (typeof window !== "undefined" && typeof window.history.replaceState === "function") {
|
|
850
|
+
window.history.replaceState(null, "", "/");
|
|
851
|
+
}
|
|
828
852
|
});
|
|
829
853
|
const setupResponseForTanstackRouter = () => {
|
|
830
854
|
// Polyfill for Response global that TanStack Router v1+ requires
|
package/index.esm.js
CHANGED
|
@@ -136,6 +136,23 @@ const ensureJestGlobalAlias = () => {
|
|
|
136
136
|
globalAny.jest = vi;
|
|
137
137
|
}
|
|
138
138
|
};
|
|
139
|
+
/**
|
|
140
|
+
* `@googlemaps/jest-mocks`' initialize() does not register TrafficLayer on
|
|
141
|
+
* `google.maps` (it only exists behind its importLibrary mock), so tests get
|
|
142
|
+
* a minimal fake with the setMap/getMap surface the Google adapter uses.
|
|
143
|
+
* Module-scoped so its prototype stays stable across tests for spying.
|
|
144
|
+
*/
|
|
145
|
+
class TrafficLayerFake {
|
|
146
|
+
constructor() {
|
|
147
|
+
this.attachedMap = null;
|
|
148
|
+
}
|
|
149
|
+
setMap(map) {
|
|
150
|
+
this.attachedMap = map;
|
|
151
|
+
}
|
|
152
|
+
getMap() {
|
|
153
|
+
return this.attachedMap;
|
|
154
|
+
}
|
|
155
|
+
}
|
|
139
156
|
/**
|
|
140
157
|
* Sets up mocks for Google Maps API and @vis.gl/react-google-maps components
|
|
141
158
|
* in testing environments.
|
|
@@ -242,6 +259,7 @@ const setupGoogleMaps = () => {
|
|
|
242
259
|
}),
|
|
243
260
|
},
|
|
244
261
|
};
|
|
262
|
+
Object.assign(global.window.google.maps, { TrafficLayer: TrafficLayerFake });
|
|
245
263
|
});
|
|
246
264
|
};
|
|
247
265
|
|
|
@@ -804,6 +822,12 @@ afterEach(async () => {
|
|
|
804
822
|
vi.clearAllMocks();
|
|
805
823
|
cleanup();
|
|
806
824
|
await flushPromisesInAct();
|
|
825
|
+
// jsdom keeps window.history across tests in a file. Reset after cleanup() so any
|
|
826
|
+
// router history has been destroyed and this is not seen as a navigation. Some specs
|
|
827
|
+
// replace window.history with a stub that has no replaceState.
|
|
828
|
+
if (typeof window !== "undefined" && typeof window.history.replaceState === "function") {
|
|
829
|
+
window.history.replaceState(null, "", "/");
|
|
830
|
+
}
|
|
807
831
|
});
|
|
808
832
|
const setupResponseForTanstackRouter = () => {
|
|
809
833
|
// Polyfill for Response global that TanStack Router v1+ requires
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@trackunit/react-vite-test-setup",
|
|
3
3
|
"description": "Test setup utilities for React applications",
|
|
4
|
-
"version": "0.0.
|
|
4
|
+
"version": "0.0.151",
|
|
5
5
|
"repository": "https://github.com/Trackunit/manager",
|
|
6
6
|
"license": "SEE LICENSE IN LICENSE.txt",
|
|
7
7
|
"engines": {
|
package/migrations/entry.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"entry.js","sourceRoot":"","sources":["../../../../../libs/react/vite-test-setup/migrations/entry.ts"],"names":[],"mappings":"","sourcesContent":["export {};\n"]}
|