Skip to content

test: cover ScratchFieldAngle wrapper-cleanup invariants#3576

Merged
cwillisf merged 1 commit intodevelopfrom
test/angle-field-double-unbind-coverage
May 1, 2026
Merged

test: cover ScratchFieldAngle wrapper-cleanup invariants#3576
cwillisf merged 1 commit intodevelopfrom
test/angle-field-double-unbind-coverage

Conversation

@cwillisf
Copy link
Copy Markdown
Contributor

@cwillisf cwillisf commented May 1, 2026

Resolves

Follow-up to #3568.

Proposed Changes

In tests/unit/scratch_field_angle.test.ts:

  • Strengthen the existing onMouseUp test with toBeUndefined checks on mouseMoveWrapper and mouseUpWrapper, asserting the wrapper-cleared contract directly rather than inferring it from unbind call count.
  • Add does not unbind drag listeners again on a second mouseup: two onMouseUp() calls produce two unbind calls, not four.
  • Add unbinds all wrappers on dispose during a drag: covers mouseDownWrapper_ cleanup, which the original test never set up.
  • Add does not unbind wrappers again on a second dispose: two dispose() calls produce three unbind calls (one per wrapper), not six.
  • Replace mockImplementation(() => {}) with mockReturnValue(() => {}) at the four spy sites. Blockly.browserEvents.unbind returns the unbound listener function, not void; the mockImplementation form was a pre-existing type mismatch.

Reason for Changes

The original test covered the onMouseUp-then-dispose path with mouseMoveWrapper and mouseUpWrapper set. Three gaps remained: mouseDownWrapper_ was never exercised, onMouseUp() and dispose() idempotency under repeated calls was untested, and the wrapper-cleared state was asserted only via unbind call count.

Each new assertion was verified against the pre-fix source at commit 2c290d27; all four tests fail under pre-fix code, each on a distinct assertion.

Test Coverage

npx vitest run tests/unit/scratch_field_angle.test.ts passes (4/4); npm run test:lint is clean.

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR strengthens unit coverage around ScratchFieldAngle’s event-wrapper cleanup contract (clearing wrapper references after Blockly.browserEvents.unbind) to ensure onMouseUp() and dispose() are idempotent and don’t trigger double-unbind errors (follow-up to #3568 / #537).

Changes:

  • Adds a makeField() helper to reduce repetition in tests.
  • Strengthens the existing mouseup→dispose test by asserting wrapper fields are cleared (toBeUndefined()).
  • Adds new tests covering repeated onMouseUp(), dispose-during-drag (including mouseDownWrapper_), and repeated dispose() idempotency.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@cwillisf cwillisf merged commit ff52af7 into develop May 1, 2026
10 checks passed
@cwillisf cwillisf deleted the test/angle-field-double-unbind-coverage branch May 1, 2026 15:11
@github-actions github-actions Bot locked and limited conversation to collaborators May 1, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants