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

Commit

Permalink
fix failing tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Alun Turner committed Apr 6, 2023
1 parent 377e191 commit 66f8380
Showing 1 changed file with 9 additions and 11 deletions.
20 changes: 9 additions & 11 deletions test/components/views/rooms/wysiwyg_composer/utils/message-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,11 @@ describe("message", () => {

beforeEach(() => {
jest.spyOn(MatrixClientPeg, "get").mockReturnValue(mockClient);
jest.clearAllMocks();
});
afterEach(() => {
jest.resetAllMocks();

afterAll(() => {
jest.restoreAllMocks();
});

describe("sendMessage", () => {
Expand Down Expand Up @@ -238,15 +240,12 @@ describe("message", () => {
expect(spyDispatcher).toHaveBeenCalledWith({ action: "effects.confetti" });
});

describe.only("slash commands", () => {
afterEach(() => {
jest.restoreAllMocks();
});
describe("slash commands", () => {
const getCommandSpy = jest.spyOn(SlashCommands, "getCommand");

it("calls getCommand for a message starting with a valid command", async () => {
// When
const validCommand = "/spoiler";
const getCommandSpy = jest.spyOn(SlashCommands, "getCommand");
await sendMessage(validCommand, true, {
roomContext: defaultRoomContext,
mxClient: mockClient,
Expand All @@ -260,7 +259,6 @@ describe("message", () => {
it("does not call getCommand for valid command with invalid prefix", async () => {
// When
const invalidPrefixCommand = "//spoiler";
const getCommandSpy = jest.spyOn(SlashCommands, "getCommand");
await sendMessage(invalidPrefixCommand, true, {
roomContext: defaultRoomContext,
mxClient: mockClient,
Expand All @@ -276,7 +274,7 @@ describe("message", () => {
it("returns undefined when the command is not successful", async () => {
// When
const validCommand = "/spoiler";
jest.spyOn(Commands, "runSlashCommand").mockResolvedValue([{ content: "mock content" }, false]);
jest.spyOn(Commands, "runSlashCommand").mockResolvedValueOnce([{ content: "mock content" }, false]);

const result = await sendMessage(validCommand, true, {
roomContext: defaultRoomContext,
Expand Down Expand Up @@ -358,7 +356,7 @@ describe("message", () => {

it("if user enters invalid command and then sends it anyway", async () => {
// mock out returning a true value for `shouldSendAnyway` to avoid rendering the modal
jest.spyOn(Commands, "shouldSendAnyway").mockResolvedValue(true);
jest.spyOn(Commands, "shouldSendAnyway").mockResolvedValueOnce(true);
const invalidCommandInput = "/badCommand";

await sendMessage(invalidCommandInput, true, {
Expand All @@ -379,7 +377,7 @@ describe("message", () => {

it("if user enters invalid command and then does not send, return undefined", async () => {
// mock out returning a true value for `shouldSendAnyway` to avoid rendering the modal
jest.spyOn(Commands, "shouldSendAnyway").mockResolvedValue(false);
jest.spyOn(Commands, "shouldSendAnyway").mockResolvedValueOnce(false);
const invalidCommandInput = "/badCommand";

const result = await sendMessage(invalidCommandInput, true, {
Expand Down

0 comments on commit 66f8380

Please sign in to comment.