Skip to content

chore(joint-react): use @joint/mock-svg for the jest SVG mocks - #3578

Merged
kumilingus merged 1 commit into
clientIO:devfrom
samuelgja:feat/joint-react-add-mock-svg-lib
Oct 29, 2026
Merged

kumilingus merged 1 commit into
clientIO:devfrom
samuelgja:feat/joint-react-add-mock-svg-lib

Conversation

@samuelgja

@samuelgja samuelgja commented Oct 29, 2026 •

Copy link
Copy Markdown
Contributor

Description

The @joint/react jest suite now takes its SVG mocks from the shared @joint/mock-svg package 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 the DOMMatrix polyfill 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:

  • The old createSVGMatrix() / createSVGPoint() returned one shared, mutable object, so V.transformPoint() returned its input and a matrix created with V.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.
  • The old checkVisibility() returned true for every element. The package reports an SVG node as rendered only when its getBBox() is non-empty, which the mock never is.
  • The package installs its mocks once per test file, not before every test.

Test changes (same behaviour verified)

  • __mocks__/jest-setup.ts: imports @joint/mock-svg; restores its ResizeObserver before 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 (checkVisibility spied to true), 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 the ResizeObserver callback with jest.spyOn(); the package mock is a plain function, not a jest.fn().

@joint/mock-svg is a dev dependency with the workspace:~ range @joint/vitest-plugin-mock-svg uses. The changeset is empty: nothing in the published package changes.

Test plan

  • yarn test in packages/joint-react on dev before the change: React 19 108 suites / 1170 tests, React 18 106 suites / 1129 tests, all passing.
  • yarn test after 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 on dev).
  • Checked which tests reach the mocks whose results changed (point and matrix transforms, 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.
  • Without the identity mapping, "moves the element when dragged" fails with the package mocks (the element stays at its position).

Context

Refs #3579.

@samuelgja samuelgja self-assigned this Oct 29, 2026
@samuelgja
samuelgja requested a review from kumilingus October 29, 2026 07:57
@kumilingus
kumilingus merged commit 06d46fd into clientIO:dev Oct 29, 2026
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants