Add comprehensive unit tests for Virtualize.ts JS module#67027
Open
ishaq2321 wants to merge 1 commit into
Open
Add comprehensive unit tests for Virtualize.ts JS module#67027ishaq2321 wants to merge 1 commit into
ishaq2321 wants to merge 1 commit into
Conversation
Author
|
@dotnet-policy-service agree |
Contributor
|
Thanks for your PR, @ishaq2321. Someone from the team will get assigned to your PR shortly and we'll get it reviewed. |
Contributor
There was a problem hiding this comment.
Pull request overview
Note
Copilot was unable to run its full agentic suite in this review.
Expands the Jest test suite for Virtualize to cover initialization branches, observer wiring, anchoring behavior, event listeners, disposal, and a basic lifecycle integration.
Changes:
- Replaced the minimal export-shape test with comprehensive unit/integration tests for
Virtualize. - Added jsdom polyfills/mocks for
CSS.supports,IntersectionObserver, andResizeObserver. - Added coverage for guard clauses, scroll-root selection, overflow-anchor modes, event listener attach/detach, and multi-component coexistence.
Comment on lines
+399
to
+401
| Virtualize.scrollToBottom(helper); | ||
| // jsdom does not support scrollTop assignment; verifying the call completes | ||
| expect(helper.invokeMethodAsync || true).toBeTruthy(); |
Comment on lines
+7
to
+8
| // ── Polyfill CSS for jsdom ─────────────────────────────────────────────── | ||
| (globalThis as any).CSS = { supports: jest.fn() as any }; |
| return el; | ||
| } | ||
|
|
||
| function installObserverMocks() { |
Comment on lines
+56
to
+57
| (globalThis as any).IntersectionObserver = io.Ctor; | ||
| (globalThis as any).ResizeObserver = ro.Ctor; |
| return { intersectionObserver: io.mock, resizeObserver: ro.mock }; | ||
| } | ||
|
|
||
| (globalThis as any)._cssSupportsOverride = true; |
| resizeObserver = m.resizeObserver; | ||
| mockCssSupports(true); | ||
| }); | ||
| afterEach(() => jest.restoreAllMocks()); |
| const { helper } = createMockDotNetObject(); | ||
| const p = createConnectedElement("div"); | ||
| Virtualize.init(helper, createConnectedElement("div", p), createConnectedElement("div", p)); | ||
| Object.defineProperty(document.documentElement, "scrollHeight", { value: 2000, writable: true }); |
Comment on lines
+371
to
+372
| const sym = Object.getOwnPropertySymbols(_callDispatcher)[0]; | ||
| expect(_callDispatcher[sym][id]).toBeDefined(); |
013dfd2 to
ff11e00
Compare
The existing Virtualize.test.ts only checked that export symbols exist. This adds 40 tests covering the full lifecycle of the Virtualize JS module used by the Blazor Virtualize component. Fixes dotnet#67029 Co-authored-by: Muhammad Ishaq Khan <muhammadishaqkhan.2321@gmail.com>
ff11e00 to
ab2bf32
Compare
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.
Fixes #67029
Summary
The existing Virtualize.test.ts (14 lines) only checked that export symbols exist. This PR adds 40 comprehensive unit tests covering the full lifecycle of the Virtualize JavaScript module.
Changes
src/Components/Web.JS/test/Virtualize.test.ts: 14 lines → 502 lines with 40 testsFinding Source
Found via
bb_security/bb_patternsstatic analysis — Virtualize.ts had complexity 139 and 0% direct JS test coverage.Co-authored-by: Muhammad Ishaq Khan muhammadishaqkhan.2321@gmail.com