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

Commit

Permalink
test: verify we actually send events for enabledMetaSpaces
Browse files Browse the repository at this point in the history
  • Loading branch information
justjanne committed May 18, 2022
1 parent 9dce9b7 commit 8f9a4cf
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions test/stores/SpaceStore-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,14 @@ See the License for the specific language governing permissions and
limitations under the License.
*/

import { EventEmitter } from "events";
import { mocked } from 'jest-mock';
import { EventType } from "matrix-js-sdk/src/@types/event";
import { RoomMember } from "matrix-js-sdk/src/models/room-member";
import { RoomStateEvent } from "matrix-js-sdk/src/models/room-state";
import { defer } from "matrix-js-sdk/src/utils";
import { ClientEvent, RoomEvent, MatrixEvent } from 'matrix-js-sdk/src/matrix';
import { useEventEmitterState } from "../../src/hooks/useEventEmitter";

import SpaceStore from "../../src/stores/spaces/SpaceStore";
import {
Expand Down Expand Up @@ -1221,4 +1223,26 @@ describe("SpaceStore", () => {
expect(SpaceStore.instance.spacePanelSpaces.map(r => r.roomId)).toStrictEqual([rootSpace.roomId]);
await prom;
});

it("correctly emits events for metaspace changes during onReady", async () => {
// similar to useEventEmitterState, but for use inside of tests
function testEventEmitterState(
emitter: EventEmitter | undefined,
eventName: string | symbol,
callback: (...args: any[]) => void,
): () => void {
callback();
emitter.addListener(eventName, callback);
return () => emitter.removeListener(eventName, callback);
}

let metaSpaces;
const removeListener = testEventEmitterState(store, UPDATE_TOP_LEVEL_SPACES, () => {
metaSpaces = store.enabledMetaSpaces;
});
expect(metaSpaces).toEqual(store.enabledMetaSpaces);
await run();
expect(metaSpaces).toEqual(store.enabledMetaSpaces);
removeListener();
});
});

0 comments on commit 8f9a4cf

Please sign in to comment.