mirror of
https://github.com/dcs-liberation/dcs_liberation.git
synced 2025-11-10 14:22:26 +00:00
Unlike the other map tests which heavily rely on mocks, this one uses React refs to inspect the constructed leaflet objects. The DOM itself doesn't appear to contain anything worth testing against (react-leaflet rendering doesn't work like typical React rendering). This required some infrastructure changes: 1. Forwarded ref from WaypointMarker to Marker so the test can observe it. Added a mergeRefs helper (and its own tests) to make that easier. 2. Switched from identity-obj-proxy to jest-transform-stub, because the former doesn't produce a useable image for imports, and we need usable images for leaflet to be able to render. This doesn't yet test drag and drop behavior since that requires mocking the backend, and this commit is already complicated enough. That'll be next.
17 lines
342 B
TypeScript
17 lines
342 B
TypeScript
import { ForwardedRef } from "react";
|
|
|
|
const mergeRefs = <T extends any>(...refs: ForwardedRef<T>[]) => {
|
|
return (node: T) => {
|
|
for (const ref of refs) {
|
|
if (ref == null) {
|
|
} else if (typeof ref === "function") {
|
|
ref(node);
|
|
} else {
|
|
ref.current = node;
|
|
}
|
|
}
|
|
};
|
|
};
|
|
|
|
export default mergeRefs;
|