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:
@@ -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;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user