-
-
Notifications
You must be signed in to change notification settings - Fork 828
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Update Jest to more recent release #11409
Changes from 17 commits
9dd3d5d
1561c54
f2b854f
8fb0790
4f03c69
b478248
2c78ec7
6840a9f
77dae84
0526efe
84c26d9
790ef21
67b0a9f
3bd5fa1
cf1a849
20a4703
fd9aa0e
70c338d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -61,17 +61,18 @@ describe("DeviceListener", () => { | |
let mockClient: Mocked<MatrixClient>; | ||
let mockCrypto: Mocked<CryptoApi>; | ||
|
||
// spy on various toasts' hide and show functions | ||
// easier than mocking | ||
jest.spyOn(SetupEncryptionToast, "showToast"); | ||
jest.spyOn(SetupEncryptionToast, "hideToast"); | ||
jest.spyOn(BulkUnverifiedSessionsToast, "showToast"); | ||
jest.spyOn(BulkUnverifiedSessionsToast, "hideToast"); | ||
jest.spyOn(UnverifiedSessionToast, "showToast"); | ||
jest.spyOn(UnverifiedSessionToast, "hideToast"); | ||
|
||
beforeEach(() => { | ||
jest.resetAllMocks(); | ||
|
||
// spy on various toasts' hide and show functions | ||
// easier than mocking | ||
jest.spyOn(SetupEncryptionToast, "showToast").mockReturnValue(undefined); | ||
jest.spyOn(SetupEncryptionToast, "hideToast").mockReturnValue(undefined); | ||
jest.spyOn(BulkUnverifiedSessionsToast, "showToast").mockReturnValue(undefined); | ||
jest.spyOn(BulkUnverifiedSessionsToast, "hideToast").mockReturnValue(undefined); | ||
jest.spyOn(UnverifiedSessionToast, "showToast").mockResolvedValue(undefined); | ||
jest.spyOn(UnverifiedSessionToast, "hideToast").mockReturnValue(undefined); | ||
Comment on lines
+67
to
+74
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. we were previously relying on resetAllMocks to make these return undefined. It doesn't any longer, so we need to do it explicitly. |
||
|
||
mockPlatformPeg({ | ||
getAppVersion: jest.fn().mockResolvedValue("1.2.3"), | ||
}); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -50,15 +50,17 @@ describe("<WidgetContextMenu />", () => { | |
avatar_url: undefined, | ||
}; | ||
|
||
const mockClient = { | ||
getUserId: jest.fn().mockReturnValue(userId), | ||
} as unknown as MatrixClient; | ||
let mockClient: MatrixClient; | ||
|
||
let onFinished: () => void; | ||
|
||
beforeEach(() => { | ||
onFinished = jest.fn(); | ||
jest.spyOn(WidgetUtils, "canUserModifyWidgets").mockReturnValue(true); | ||
|
||
mockClient = { | ||
getUserId: jest.fn().mockReturnValue(userId), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
} as unknown as MatrixClient; | ||
}); | ||
|
||
afterEach(() => { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -29,6 +29,7 @@ import { | |
setupAsyncStoreWithClient, | ||
resetAsyncStoreWithClient, | ||
wrapInMatrixClientContext, | ||
useMockMediaDevices, | ||
} from "../../../test-utils"; | ||
import defaultDispatcher from "../../../../src/dispatcher/dispatcher"; | ||
import { Action } from "../../../../src/dispatcher/actions"; | ||
|
@@ -41,9 +42,6 @@ import { ConnectionState } from "../../../../src/models/Call"; | |
const CallEvent = wrapInMatrixClientContext(UnwrappedCallEvent); | ||
|
||
describe("CallEvent", () => { | ||
useMockedCalls(); | ||
jest.spyOn(HTMLMediaElement.prototype, "play").mockImplementation(async () => {}); | ||
|
||
let client: Mocked<MatrixClient>; | ||
let room: Room; | ||
let alice: RoomMember; | ||
|
@@ -55,6 +53,10 @@ describe("CallEvent", () => { | |
jest.useFakeTimers(); | ||
jest.setSystemTime(0); | ||
|
||
useMockMediaDevices(); | ||
useMockedCalls(); | ||
jest.spyOn(HTMLMediaElement.prototype, "play").mockImplementation(async () => {}); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. move these in here from the top of the |
||
|
||
stubClient(); | ||
client = mocked(MatrixClientPeg.safeGet()); | ||
client.getUserId.mockReturnValue("@alice:example.org"); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,8 +15,8 @@ limitations under the License. | |
*/ | ||
|
||
import React from "react"; | ||
import { fireEvent, render } from "@testing-library/react"; | ||
import { Filter, EventTimeline, Room } from "matrix-js-sdk/src/matrix"; | ||
import { act, fireEvent, render } from "@testing-library/react"; | ||
import { Filter, EventTimeline, Room, MatrixEvent } from "matrix-js-sdk/src/matrix"; | ||
import { M_POLL_START } from "matrix-js-sdk/src/@types/polls"; | ||
|
||
import { PollHistory } from "../../../../../src/components/views/polls/pollHistory/PollHistory"; | ||
|
@@ -194,7 +194,11 @@ describe("<PollHistory />", () => { | |
const fourtyDaysAgoTs = now - 60000 * 60 * 24 * 40; | ||
const pollStart = makePollStartEvent("Question?", userId, undefined, { ts: fourtyDaysAgoTs, id: "1" }); | ||
|
||
jest.spyOn(liveTimeline, "getEvents").mockReset().mockReturnValueOnce([]).mockReturnValueOnce([pollStart]); | ||
jest.spyOn(liveTimeline, "getEvents") | ||
.mockReset() | ||
.mockReturnValueOnce([]) | ||
.mockReturnValueOnce([pollStart]) | ||
.mockReturnValue(undefined as unknown as MatrixEvent[]); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this is necessary due to a change in the way https://jestjs.io/docs/29.3/mock-function-api#mockfnmockreset says:
This no longer appears to be the case as of 29.6 and we now get the original implementation instead. So, to preserve current behaviour, have it return |
||
|
||
// mock three pages of timeline history | ||
jest.spyOn(liveTimeline, "getPaginationToken") | ||
|
@@ -203,7 +207,7 @@ describe("<PollHistory />", () => { | |
.mockReturnValueOnce("test-pagination-token-3"); | ||
|
||
const { getByText } = getComponent(); | ||
await flushPromises(); | ||
await act(flushPromises); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. shoved some things in |
||
|
||
expect(mockClient.paginateEventTimeline).toHaveBeenCalledTimes(1); | ||
|
||
|
@@ -216,7 +220,7 @@ describe("<PollHistory />", () => { | |
// load more polls button still in UI, with loader | ||
expect(getByText("Load more polls")).toMatchSnapshot(); | ||
|
||
await flushPromises(); | ||
await act(flushPromises); | ||
|
||
// no more spinner | ||
expect(getByText("Load more polls")).toMatchSnapshot(); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -73,6 +73,10 @@ const classes = { | |
}; | ||
|
||
describe("FormattingButtons", () => { | ||
beforeEach(() => { | ||
openLinkModalSpy.mockReturnValue(undefined); | ||
}); | ||
Comment on lines
+76
to
+78
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. we were previously relying on |
||
|
||
afterEach(() => { | ||
jest.resetAllMocks(); | ||
}); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -28,7 +28,7 @@ describe("<SidebarUserSettingsTab />", () => { | |
beforeEach(() => { | ||
jest.spyOn(PosthogTrackers, "trackInteraction").mockClear(); | ||
jest.spyOn(SettingsStore, "getValue").mockRestore(); | ||
jest.spyOn(SettingsStore, "setValue").mockReset(); | ||
jest.spyOn(SettingsStore, "setValue").mockResolvedValue(undefined); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. another case of |
||
}); | ||
|
||
it("renders sidebar settings", () => { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -24,12 +24,12 @@ import SdkConfig from "../../../../src/SdkConfig"; | |
|
||
jest.mock("../../../../src/components/structures/EmbeddedPage", () => ({ | ||
__esModule: true, | ||
default: jest.fn().mockImplementation(({ url }) => <div>{url}</div>), | ||
default: ({ url }: { url: string }) => <div>{url}</div>, | ||
})); | ||
|
||
jest.mock("../../../../src/components/structures/HomePage", () => ({ | ||
__esModule: true, | ||
default: jest.fn().mockImplementation(() => <div>home page</div>), | ||
default: () => <div>home page</div>, | ||
Comment on lines
-27
to
+32
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. avoid these being reset by |
||
})); | ||
|
||
describe("UserOnboardingPage", () => { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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) => ({ | ||
Comment on lines
+59
to
+60
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. avoid this being reset by |
||
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 | ||
|
@@ -91,11 +92,3 @@ window.fetch = fetchMock.sandbox(); | |
|
||
// @ts-ignore | ||
window.Response = Response; | ||
|
||
// set up mediaDevices mock | ||
Object.defineProperty(navigator, "mediaDevices", { | ||
value: { | ||
enumerateDevices: jest.fn().mockResolvedValue([]), | ||
getUserMedia: jest.fn(), | ||
}, | ||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
looks like this was previously being pulled in transitively, but is no more.