Update Jest to more recent release (#11409)

* Update Jest to more recent release

I want to use things like `jest.advanceTimersByTimeAsync`

* more jest updates

* add dep on types/prettier

* fix LegacyRoomHeader-test

* fix MatrixChat-test

* fix RoomView-test

* fix PollHistory-test

* update SidebarUserSettingsTab-test

* fix PipContainer-test

* fix UserOnboardingPage-test

* fix WidgetContextMenu-test.tsx

* Avoid `mockImplementation` for mock `matchMedia` impl

`mockImplementation` is (now) reset by `jest.resetAllMocks` and
`jest.restoreAllMocks`, which we don't really want here.

Fixes `theme-test`

* 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.

* fix FormattingButtons-test.tsx

* fix DeviceListenerTest

* fix RoomTile-test
This commit is contained in:
Richard van der Hoff 2023-08-16 11:20:48 +01:00 committed by GitHub
parent f8e1c54768
commit 7a6d81c3b8
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
14 changed files with 512 additions and 350 deletions

View file

@ -56,7 +56,8 @@ class MyClipboardEvent extends Event {}
window.ClipboardEvent = MyClipboardEvent as any;
// matchMedia is not included in jsdom
const mockMatchMedia = jest.fn().mockImplementation((query) => ({
// TODO: Extract this to a function and have tests that need it opt into it.
const mockMatchMedia = (query: string) => ({
matches: false,
media: query,
onchange: null,
@ -65,7 +66,7 @@ const mockMatchMedia = jest.fn().mockImplementation((query) => ({
addEventListener: jest.fn(),
removeEventListener: jest.fn(),
dispatchEvent: jest.fn(),
}));
});
global.matchMedia = mockMatchMedia;
// maplibre requires a createObjectURL mock