Repository navigation
chore(joint-react): use @joint/mock-svg for the jest SVG mocks - #3578
Merged
kumilingus merged 1 commit intoOct 29, 2026
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
The
@joint/reactjest suite now takes its SVG mocks from the shared@joint/mock-svgpackage instead of its own copy in__mocks__/jest-setup.ts. The hand-rolled mocks (SVGPathElement,SVGAngle,ResizeObserver,createSVGMatrix/createSVGPoint/createSVGTransform,getBBox,getScreenCTM,getComputedTextLength,checkVisibility) are removed; only theDOMMatrixpolyfill stays, since the package does not provide it.The package mocks are closer to a browser without layout than the old ones, which leaked state between calls:
createSVGMatrix()/createSVGPoint()returned one shared, mutable object, soV.transformPoint()returned its input and a matrix created withV.createSVGMatrix()kept the values written into it. The package returns a fresh all-zero point / matrix each time: every client point maps to the paper origin.checkVisibility()returnedtruefor every element. The package reports an SVG node as rendered only when itsgetBBox()is non-empty, which the mock never is.Test changes (same behaviour verified)
__mocks__/jest-setup.ts: imports@joint/mock-svg; restores itsResizeObserverbefore every test, so the suites that install their own observer stay isolated, as with the per-test reinstall before.paper-button-interactions.test.tsx: the paper maps client points to local points one-to-one (it sits unscaled at the client origin). The drag test relied on the leaking matrix to move the element; with the identity mapping both cases (drag moves, press-and-release does not) are checked against a working pointer mapping.anchors.test.ts,extra-coverage.test.ts: magnets are treated as rendered (checkVisibilityspied totrue), so the DOM-measured fallbacks still measure the magnet instead of hitting the "not part of the render tree" branch.graph-store.test.ts: captures theResizeObservercallback withjest.spyOn(); the package mock is a plain function, not ajest.fn().@joint/mock-svgis a dev dependency with theworkspace:~range@joint/vitest-plugin-mock-svguses. The changeset is empty: nothing in the published package changes.Test plan
yarn testinpackages/joint-reactondevbefore the change: React 19 108 suites / 1170 tests, React 18 106 suites / 1129 tests, all passing.yarn testafter the change: the same 108 / 1170 and 106 / 1129, all passing; typecheck, knip and jscpd pass.yarn lint: 0 errors (the 2 warnings are already ondev).checkVisibility,transform.baseVal). Apart from the files above, they assert events, classes or that a value exists, not coordinates, so none of them passes on a value the old mocks produced by accident.Context
Refs #3579.