@@ -66,9 +66,11 @@ describe("message", () => {
6666
6767 beforeEach ( ( ) => {
6868 jest . spyOn ( MatrixClientPeg , "get" ) . mockReturnValue ( mockClient ) ;
69+ jest . clearAllMocks ( ) ;
6970 } ) ;
70- afterEach ( ( ) => {
71- jest . resetAllMocks ( ) ;
71+
72+ afterAll ( ( ) => {
73+ jest . restoreAllMocks ( ) ;
7274 } ) ;
7375
7476 describe ( "sendMessage" , ( ) => {
@@ -238,15 +240,12 @@ describe("message", () => {
238240 expect ( spyDispatcher ) . toHaveBeenCalledWith ( { action : "effects.confetti" } ) ;
239241 } ) ;
240242
241- describe . only ( "slash commands" , ( ) => {
242- afterEach ( ( ) => {
243- jest . restoreAllMocks ( ) ;
244- } ) ;
243+ describe ( "slash commands" , ( ) => {
244+ const getCommandSpy = jest . spyOn ( SlashCommands , "getCommand" ) ;
245245
246246 it ( "calls getCommand for a message starting with a valid command" , async ( ) => {
247247 // When
248248 const validCommand = "/spoiler" ;
249- const getCommandSpy = jest . spyOn ( SlashCommands , "getCommand" ) ;
250249 await sendMessage ( validCommand , true , {
251250 roomContext : defaultRoomContext ,
252251 mxClient : mockClient ,
@@ -260,7 +259,6 @@ describe("message", () => {
260259 it ( "does not call getCommand for valid command with invalid prefix" , async ( ) => {
261260 // When
262261 const invalidPrefixCommand = "//spoiler" ;
263- const getCommandSpy = jest . spyOn ( SlashCommands , "getCommand" ) ;
264262 await sendMessage ( invalidPrefixCommand , true , {
265263 roomContext : defaultRoomContext ,
266264 mxClient : mockClient ,
@@ -276,7 +274,7 @@ describe("message", () => {
276274 it ( "returns undefined when the command is not successful" , async ( ) => {
277275 // When
278276 const validCommand = "/spoiler" ;
279- jest . spyOn ( Commands , "runSlashCommand" ) . mockResolvedValue ( [ { content : "mock content" } , false ] ) ;
277+ jest . spyOn ( Commands , "runSlashCommand" ) . mockResolvedValueOnce ( [ { content : "mock content" } , false ] ) ;
280278
281279 const result = await sendMessage ( validCommand , true , {
282280 roomContext : defaultRoomContext ,
@@ -358,7 +356,7 @@ describe("message", () => {
358356
359357 it ( "if user enters invalid command and then sends it anyway" , async ( ) => {
360358 // mock out returning a true value for `shouldSendAnyway` to avoid rendering the modal
361- jest . spyOn ( Commands , "shouldSendAnyway" ) . mockResolvedValue ( true ) ;
359+ jest . spyOn ( Commands , "shouldSendAnyway" ) . mockResolvedValueOnce ( true ) ;
362360 const invalidCommandInput = "/badCommand" ;
363361
364362 await sendMessage ( invalidCommandInput , true , {
@@ -379,7 +377,7 @@ describe("message", () => {
379377
380378 it ( "if user enters invalid command and then does not send, return undefined" , async ( ) => {
381379 // mock out returning a true value for `shouldSendAnyway` to avoid rendering the modal
382- jest . spyOn ( Commands , "shouldSendAnyway" ) . mockResolvedValue ( false ) ;
380+ jest . spyOn ( Commands , "shouldSendAnyway" ) . mockResolvedValueOnce ( false ) ;
383381 const invalidCommandInput = "/badCommand" ;
384382
385383 const result = await sendMessage ( invalidCommandInput , true , {
0 commit comments