test: cover ScratchFieldAngle wrapper-cleanup invariants#3576
Merged
test: cover ScratchFieldAngle wrapper-cleanup invariants#3576
Conversation
Contributor
There was a problem hiding this comment.
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 (includingmouseDownWrapper_), and repeateddispose()idempotency.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
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 subscribe to this conversation on GitHub.
Already have an account?
Sign in.
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.
Resolves
Follow-up to #3568.
Proposed Changes
In
tests/unit/scratch_field_angle.test.ts:onMouseUptest withtoBeUndefinedchecks onmouseMoveWrapperandmouseUpWrapper, asserting the wrapper-cleared contract directly rather than inferring it fromunbindcall count.does not unbind drag listeners again on a second mouseup: twoonMouseUp()calls produce twounbindcalls, not four.unbinds all wrappers on dispose during a drag: coversmouseDownWrapper_cleanup, which the original test never set up.does not unbind wrappers again on a second dispose: twodispose()calls produce threeunbindcalls (one per wrapper), not six.mockImplementation(() => {})withmockReturnValue(() => {})at the four spy sites.Blockly.browserEvents.unbindreturns the unbound listener function, notvoid; themockImplementationform was a pre-existing type mismatch.Reason for Changes
The original test covered the onMouseUp-then-dispose path with
mouseMoveWrapperandmouseUpWrapperset. Three gaps remained:mouseDownWrapper_was never exercised,onMouseUp()anddispose()idempotency under repeated calls was untested, and the wrapper-cleared state was asserted only viaunbindcall 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.tspasses (4/4);npm run test:lintis clean.