Mock web-vitals globally in test setup

ScenarioMonitor subscribes to web-vitals when it is imported, so the onTTFB timer can throw during any suite that outlives it. Mocking it in setupTests.ts keeps that out of individual test files.
This commit is contained in:
Asier Isayas
2026-08-26 15:31:55 -04:00
parent 527fc2c48c
commit b2d40ad9ce
3 changed files with 5 additions and 8 deletions
@@ -1,8 +1,5 @@
jest.mock("../../../hooks/useDirectories");
jest.mock("../../../Common/PortalBackendClient");
// ScenarioMonitor subscribes to web-vitals on import, and onTTFB reads a navigation timing entry that
// jsdom never produces, throwing from a timer that lands on whichever test happens to be running.
jest.mock("web-vitals");
import "@testing-library/jest-dom";
import { fireEvent, render, screen } from "@testing-library/react";
import { extractFeatures } from "Platform/Hosted/extractFeatures";
@@ -16,8 +13,7 @@ const mockIsAccountRestricted = isAccountRestrictedForConnectionStringLogin as j
typeof isAccountRestrictedForConnectionStringLogin
>;
// fetchEncryptedToken rejects with the raw Response. jsdom implements no part of the fetch API, so
// there is no Response constructor to build one with.
// fetchEncryptedToken rejects with the raw Response.
const rejectWithResponse = (status: number, body: string) =>
mockFetchEncryptedToken.mockRejectedValue({ status, text: async () => body } as Response);
@@ -8,9 +8,7 @@ const DnsPort = "443";
const isPpeZone = (zone: string): boolean => zone === PpeDnsSuffix || zone.endsWith(`.${PpeDnsSuffix}`);
// Picks the DNS zone matching the kind of account the connection string came from, since a PPE
// account's endpoints sit under PPE zones and every other account's do not. Returns undefined when the
// config carries no zone of that kind, so the caller can reject the connection string rather than build
// an endpoint the account does not own and send the account key there.
// account's endpoints sit under PPE zones and every other account's do not.
export const selectEndpointZone = (zones: ReadonlyArray<string>, isPpeAccount: boolean): string | undefined =>
zones.find((zone) => isPpeZone(zone) === isPpeAccount);
+3
View File
@@ -6,6 +6,9 @@ import enableHooks from "jest-react-hooks-shallow";
import { TextDecoder, TextEncoder } from "util";
import i18n from "./i18n";
import enResources from "./Localization/en/Resources.json";
jest.mock("web-vitals");
configure({ adapter: new Adapter() });
initializeIcons();