mirror of
https://github.com/Azure/cosmos-explorer.git
synced 2026-08-30 02:08:40 +01:00
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:
@@ -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);
|
||||
|
||||
|
||||
@@ -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();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user