Skip to content

Add comprehensive unit tests for Virtualize.ts JS module#67027

Open
ishaq2321 wants to merge 1 commit into
dotnet:mainfrom
ishaq2321:test/virtualize-js-unit-tests
Open

Add comprehensive unit tests for Virtualize.ts JS module#67027
ishaq2321 wants to merge 1 commit into
dotnet:mainfrom
ishaq2321:test/virtualize-js-unit-tests

Conversation

@ishaq2321
Copy link
Copy Markdown

@ishaq2321 ishaq2321 commented Jun 5, 2026

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 tests
  • Tests use Jest + jsdom with mocked IntersectionObserver/ResizeObserver

Finding Source

Found via bb_security / bb_patterns static analysis — Virtualize.ts had complexity 139 and 0% direct JS test coverage.

Co-authored-by: Muhammad Ishaq Khan muhammadishaqkhan.2321@gmail.com

Copilot AI review requested due to automatic review settings June 5, 2026 00:14
@ishaq2321 ishaq2321 requested a review from a team as a code owner June 5, 2026 00:14
@ishaq2321
Copy link
Copy Markdown
Author

@dotnet-policy-service agree

@github-actions github-actions Bot added the area-blazor Includes: Blazor, Razor Components label Jun 5, 2026
@dotnet-policy-service dotnet-policy-service Bot added the community-contribution Indicates that the PR has been added by a community member label Jun 5, 2026
@dotnet-policy-service
Copy link
Copy Markdown
Contributor

Thanks for your PR, @ishaq2321. Someone from the team will get assigned to your PR shortly and we'll get it reviewed.

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

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, and ResizeObserver.
  • 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();
@ishaq2321 ishaq2321 force-pushed the test/virtualize-js-unit-tests branch from 013dfd2 to ff11e00 Compare June 5, 2026 00:18
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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area-blazor Includes: Blazor, Razor Components community-contribution Indicates that the PR has been added by a community member

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add comprehensive unit tests for Virtualize.ts JavaScript module

2 participants