@@ -66,9 +66,11 @@ describe("message", () => {
66
66
67
67
beforeEach ( ( ) => {
68
68
jest . spyOn ( MatrixClientPeg , "get" ) . mockReturnValue ( mockClient ) ;
69
+ jest . clearAllMocks ( ) ;
69
70
} ) ;
70
- afterEach ( ( ) => {
71
- jest . resetAllMocks ( ) ;
71
+
72
+ afterAll ( ( ) => {
73
+ jest . restoreAllMocks ( ) ;
72
74
} ) ;
73
75
74
76
describe ( "sendMessage" , ( ) => {
@@ -238,15 +240,12 @@ describe("message", () => {
238
240
expect ( spyDispatcher ) . toHaveBeenCalledWith ( { action : "effects.confetti" } ) ;
239
241
} ) ;
240
242
241
- describe . only ( "slash commands" , ( ) => {
242
- afterEach ( ( ) => {
243
- jest . restoreAllMocks ( ) ;
244
- } ) ;
243
+ describe ( "slash commands" , ( ) => {
244
+ const getCommandSpy = jest . spyOn ( SlashCommands , "getCommand" ) ;
245
245
246
246
it ( "calls getCommand for a message starting with a valid command" , async ( ) => {
247
247
// When
248
248
const validCommand = "/spoiler" ;
249
- const getCommandSpy = jest . spyOn ( SlashCommands , "getCommand" ) ;
250
249
await sendMessage ( validCommand , true , {
251
250
roomContext : defaultRoomContext ,
252
251
mxClient : mockClient ,
@@ -260,7 +259,6 @@ describe("message", () => {
260
259
it ( "does not call getCommand for valid command with invalid prefix" , async ( ) => {
261
260
// When
262
261
const invalidPrefixCommand = "//spoiler" ;
263
- const getCommandSpy = jest . spyOn ( SlashCommands , "getCommand" ) ;
264
262
await sendMessage ( invalidPrefixCommand , true , {
265
263
roomContext : defaultRoomContext ,
266
264
mxClient : mockClient ,
@@ -276,7 +274,7 @@ describe("message", () => {
276
274
it ( "returns undefined when the command is not successful" , async ( ) => {
277
275
// When
278
276
const validCommand = "/spoiler" ;
279
- jest . spyOn ( Commands , "runSlashCommand" ) . mockResolvedValue ( [ { content : "mock content" } , false ] ) ;
277
+ jest . spyOn ( Commands , "runSlashCommand" ) . mockResolvedValueOnce ( [ { content : "mock content" } , false ] ) ;
280
278
281
279
const result = await sendMessage ( validCommand , true , {
282
280
roomContext : defaultRoomContext ,
@@ -358,7 +356,7 @@ describe("message", () => {
358
356
359
357
it ( "if user enters invalid command and then sends it anyway" , async ( ) => {
360
358
// 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 ) ;
362
360
const invalidCommandInput = "/badCommand" ;
363
361
364
362
await sendMessage ( invalidCommandInput , true , {
@@ -379,7 +377,7 @@ describe("message", () => {
379
377
380
378
it ( "if user enters invalid command and then does not send, return undefined" , async ( ) => {
381
379
// 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 ) ;
383
381
const invalidCommandInput = "/badCommand" ;
384
382
385
383
const result = await sendMessage ( invalidCommandInput , true , {
0 commit comments