Migrate batch of tests to vitest (#34106)

* Migrate autocomplete tests to vitest

* Migrate utils/beacon tests to vitest

* Migrate utils/device tests to vitest

* Migrate utils/crypto tests to vitest

* Migrate utils/localRoom tests to vitest

* Migrate notifications tests to vitest

* Fix types

* Make jest test happy

* Make sonar happier
This commit is contained in:
Michael Telatynski
2026-07-03 10:10:04 +00:00
committed by GitHub
parent 78273c569b
commit 275ea25eca
21 changed files with 195 additions and 147 deletions
+10 -5
View File
@@ -20,6 +20,7 @@ import {
import { getMockGeolocationPositionError } from "./location";
import { makeRoomWithStateEvents } from "./room";
import { vi, isJest } from "../setup/adapter.ts";
type InfoContentProps = {
timeout: number;
@@ -132,14 +133,18 @@ export const makeGeolocationPosition = ({
*/
export const mockGeolocation = (): MockedObject<Geolocation> => {
const mockGeolocation = {
clearWatch: jest.fn(),
getCurrentPosition: jest.fn().mockImplementation((callback) => callback(makeGeolocationPosition({}))),
watchPosition: jest.fn().mockImplementation((callback) => callback(makeGeolocationPosition({}))),
clearWatch: vi.fn(),
getCurrentPosition: vi.fn().mockImplementation((callback) => callback(makeGeolocationPosition({}))),
watchPosition: vi.fn().mockImplementation((callback) => callback(makeGeolocationPosition({}))),
} as unknown as MockedObject<Geolocation>;
// jest jsdom does not provide geolocation
// @ts-ignore illegal assignment to readonly property
navigator.geolocation = mockGeolocation;
if (isJest) {
// @ts-ignore illegal assignment to readonly property
navigator.geolocation = mockGeolocation;
} else {
vi.spyOn(navigator, "geolocation", "get").mockReturnValue(mockGeolocation);
}
return mockGeolocation;
};