Skip to content
This repository was archived by the owner on Sep 11, 2024. It is now read-only.

Commit 7616f71

Browse files
committed
TS
1 parent 6ec2523 commit 7616f71

File tree

1 file changed

+13
-7
lines changed

1 file changed

+13
-7
lines changed

test/hooks/useSlidingSyncRoomSearch-test.tsx

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -23,22 +23,28 @@ import { mocked } from "jest-mock";
2323
import { SlidingSync } from "matrix-js-sdk/src/sliding-sync";
2424
import { Room } from "matrix-js-sdk/src/matrix";
2525

26-
import { useSlidingSyncRoomSearch } from "../../src/hooks/useSlidingSyncRoomSearch";
26+
import { SlidingSyncRoomSearchOpts, useSlidingSyncRoomSearch } from "../../src/hooks/useSlidingSyncRoomSearch";
2727
import { MockEventEmitter, stubClient } from "../test-utils";
2828
import { SlidingSyncManager } from "../../src/SlidingSyncManager";
2929

30+
type RoomSearchHook = {
31+
loading: boolean;
32+
rooms: Room[];
33+
search(opts: SlidingSyncRoomSearchOpts): Promise<boolean>;
34+
};
35+
3036
// hooks must be inside a React component else you get:
3137
// "Invalid hook call. Hooks can only be called inside of the body of a function component."
32-
function RoomSearchComponent({ onClick }) {
38+
function RoomSearchComponent(props: { onClick: (h: RoomSearchHook) => void }) {
3339
const roomSearch = useSlidingSyncRoomSearch();
34-
return <div onClick={() => onClick(roomSearch)} />;
40+
return <div onClick={() => props.onClick(roomSearch)} />;
3541
}
3642

3743
describe("useSlidingSyncRoomSearch", () => {
3844
it("should display rooms when searching", async () => {
3945
const client = stubClient();
40-
const roomA = new Room("!a:localhost", client, client.getUserId());
41-
const roomB = new Room("!b:localhost", client, client.getUserId());
46+
const roomA = new Room("!a:localhost", client, client.getUserId()!);
47+
const roomB = new Room("!b:localhost", client, client.getUserId()!);
4248
const slidingSync = mocked(
4349
new MockEventEmitter({
4450
getListData: jest.fn(),
@@ -67,7 +73,7 @@ describe("useSlidingSyncRoomSearch", () => {
6773
});
6874

6975
// first check that everything is empty and then do the search
70-
let executeHook = (roomSearch) => {
76+
let executeHook = (roomSearch: RoomSearchHook) => {
7177
expect(roomSearch.loading).toBe(false);
7278
expect(roomSearch.rooms).toEqual([]);
7379
roomSearch.search({
@@ -77,7 +83,7 @@ describe("useSlidingSyncRoomSearch", () => {
7783
};
7884
const wrapper = mount(
7985
<RoomSearchComponent
80-
onClick={(roomSearch) => {
86+
onClick={(roomSearch: RoomSearchHook) => {
8187
executeHook(roomSearch);
8288
}}
8389
/>,

0 commit comments

Comments
 (0)