Skip to content

Conversation

@danielle-soaress
Copy link

Description

This pull request introduces a comprehensive suite of unit tests for the eraserTest function, which is part of the Eraser module in the Excalidraw project. The goal is to improve test coverage and ensure the correctness of the eraser’s behavior when interacting with various element types on the canvas.

The eraserTest function determines whether a segment of the eraser path intersects or affects an element, deciding whether it should be removed. It is a core part of the EraserTrail feature, responsible for interactive element deletion.

Changes Introduced

  • Added a new test file: packages/excalidraw/tests/eraser.test.tsx

  • Implemented 7 new test cases (CT1–CT7) covering different interaction scenarios between the eraser and elements:
    - Rectangles, lines (open and closed), arrows, and polygons.
    - Both positive (element should be erased) and negative (element should remain) cases.

  • Created mock modules to isolate behavior:
    - @excalidraw/element mock for simplified geometry and element checks (isArrowElement, isLineElement, shouldTestInside, etc.).
    - @excalidraw/math mock for geometric operations like lineSegmentsDistance and polygonIncludesPointNonZero.

  • Included TODO comments for future improvements such as testing grouped elements, linked text, zoom variations, and complex FreeDraw cases.

Test Results

All newly implemented tests passed successfully.

Metric Before After
Statements 22.22% (68/306) 57.84% (177/306)
Branches 100% (5/5) 61.53% (16/26)
Functions 33.33% (3/9) 88.88% (8/9)
Lines 22.22% (68/306) 57.84% (177/306)

The number of tested functions nearly tripled, and over half of the eraser module’s logic is now covered by automated tests. Although branch coverage percentage decreased due to a higher number of conditional paths being tracked, the total tested logic increased substantially.

Next Steps (TO-DO)

Add tests for:

  • Grouped elements and bound text containers.
  • Different zoom levels and stroke widths.
  • FreeDraw and complex polygon cases.
  • Edge cases such as very short eraser paths.

References

Function under test: eraserTest

Test implementation: eraser.test.tsx

Commit: 3230a82

Added unit tests CT1 to CT7 to validate EraserTrail behavior with rectangles, lines (open and polygon), and arrows. Mocks for @excalidraw/element and @excalidraw/math ensure isolated, predictable testing without relying on DOM or complex calculations. TO-DOs included for future coverage of groups, bound text, containers, freedraw, zoom/stroke extremes, and minimal paths.
@vercel
Copy link

vercel bot commented Oct 31, 2025

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Preview Updated (UTC)
excalidraw Ready Ready Preview Oct 31, 2025 5:07pm

@vercel
Copy link

vercel bot commented Oct 31, 2025

@danielle-soaress is attempting to deploy a commit to the Excalidraw Team on Vercel.

A member of the Team first needs to authorize it.

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.

1 participant