@@ -22,6 +22,7 @@ import { MatrixClient } from "../../src/client";
2222import { ToDeviceBatch } from '../../src/models/ToDeviceMessage' ;
2323import { logger } from '../../src/logger' ;
2424import { IStore } from '../../src/store' ;
25+ import { removeElement } from "../../src/utils" ;
2526
2627const FAKE_USER = "@alice:example.org" ;
2728const FAKE_DEVICE_ID = "AAAAAAAA" ;
@@ -75,6 +76,8 @@ describe.each([
7576 let client : MatrixClient ;
7677
7778 beforeEach ( async function ( ) {
79+ jest . runOnlyPendingTimers ( ) ;
80+ jest . useRealTimers ( ) ;
7881 httpBackend = new MockHttpBackend ( ) ;
7982
8083 let store : IStore ;
@@ -300,7 +303,7 @@ describe.each([
300303 ] ,
301304 } ) ;
302305
303- expect ( await httpBackend . flush ( undefined , 1 , 1 ) ) . toEqual ( 1 ) ;
306+ expect ( await httpBackend . flush ( undefined , 1 , 20 ) ) . toEqual ( 1 ) ;
304307 await flushPromises ( ) ;
305308
306309 const dummyEvent = new MatrixEvent ( {
@@ -328,12 +331,12 @@ describe.each([
328331 } ) ;
329332 }
330333
334+ const expectedCounts = [ 20 , 1 ] ;
331335 httpBackend . when (
332336 "PUT" , "/sendToDevice/org.example.foo/" ,
333337 ) . check ( ( request ) => {
334- expect ( Object . keys ( request . data . messages ) . length ) . toEqual ( 20 ) ;
338+ expect ( removeElement ( expectedCounts , c => c === Object . keys ( request . data . messages ) . length ) ) . toBeTruthy ( ) ;
335339 } ) . respond ( 200 , { } ) ;
336-
337340 httpBackend . when (
338341 "PUT" , "/sendToDevice/org.example.foo/" ,
339342 ) . check ( ( request ) => {
0 commit comments