Move mediaDevices mock out of setupManualMocks (#11413)

* Move `mediaDevices` mock out of `setupManualMocks`

This doesn't work well in test suites with multiple tests, because the
`mockReturnValue` is reset for subsequent tests.

In any case, having it mocked out automagically is *magical*. Let's make it
opt-in.

* clarify ts-ignore
This commit is contained in:
Richard van der Hoff 2023-08-16 09:29:34 +01:00 committed by GitHub
parent d569ba0cfe
commit 3fda0299a5
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
9 changed files with 34 additions and 15 deletions

View file

@ -225,3 +225,12 @@ export const clearAllModals = async (): Promise<void> => {
}
}
};
/** Install a stub object at `navigator.mediaDevices` */
export function useMockMediaDevices(): void {
// @ts-ignore assignment of a thing that isn't a `MediaDevices` to read-only property
navigator["mediaDevices"] = {
enumerateDevices: jest.fn().mockResolvedValue([]),
getUserMedia: jest.fn(),
};
}