@@ -139,6 +139,9 @@ describe("MatrixClient", function() {
139139 store . getSavedSync = expect . createSpy ( ) . andReturn ( Promise . resolve ( null ) ) ;
140140 store . getSavedSyncToken = expect . createSpy ( ) . andReturn ( Promise . resolve ( null ) ) ;
141141 store . setSyncData = expect . createSpy ( ) . andReturn ( Promise . resolve ( null ) ) ;
142+ store . getClientOptions = expect . createSpy ( ) . andReturn ( Promise . resolve ( null ) ) ;
143+ store . storeClientOptions = expect . createSpy ( ) . andReturn ( Promise . resolve ( null ) ) ;
144+ store . isNewlyCreated = expect . createSpy ( ) . andReturn ( Promise . resolve ( true ) ) ;
142145 client = new MatrixClient ( {
143146 baseUrl : "https://my.home.server" ,
144147 idBaseUrl : identityServerUrl ,
@@ -182,7 +185,7 @@ describe("MatrixClient", function() {
182185 } ) ;
183186 } ) ;
184187
185- it ( "should not POST /filter if a matching filter already exists" , function ( done ) {
188+ it ( "should not POST /filter if a matching filter already exists" , async function ( ) {
186189 httpLookups = [ ] ;
187190 httpLookups . push ( PUSH_RULES_RESPONSE ) ;
188191 httpLookups . push ( SYNC_RESPONSE ) ;
@@ -191,31 +194,38 @@ describe("MatrixClient", function() {
191194 const filter = new sdk . Filter ( 0 , filterId ) ;
192195 filter . setDefinition ( { "room" : { "timeline" : { "limit" : 8 } } } ) ;
193196 store . getFilter . andReturn ( filter ) ;
194- client . startClient ( ) ;
195-
196- client . on ( "sync" , function syncListener ( state ) {
197- if ( state === "SYNCING" ) {
198- expect ( httpLookups . length ) . toEqual ( 0 ) ;
199- client . removeListener ( "sync" , syncListener ) ;
200- done ( ) ;
201- }
197+ const syncPromise = new Promise ( ( resolve , reject ) => {
198+ client . on ( "sync" , function syncListener ( state ) {
199+ if ( state === "SYNCING" ) {
200+ expect ( httpLookups . length ) . toEqual ( 0 ) ;
201+ client . removeListener ( "sync" , syncListener ) ;
202+ resolve ( ) ;
203+ } else if ( state === "ERROR" ) {
204+ reject ( new Error ( "sync error" ) ) ;
205+ }
206+ } ) ;
202207 } ) ;
208+ await client . startClient ( ) ;
209+ await syncPromise ;
203210 } ) ;
204211
205212 describe ( "getSyncState" , function ( ) {
206213 it ( "should return null if the client isn't started" , function ( ) {
207214 expect ( client . getSyncState ( ) ) . toBe ( null ) ;
208215 } ) ;
209216
210- it ( "should return the same sync state as emitted sync events" , function ( done ) {
211- client . on ( "sync" , function syncListener ( state ) {
212- expect ( state ) . toEqual ( client . getSyncState ( ) ) ;
213- if ( state === "SYNCING" ) {
214- client . removeListener ( "sync" , syncListener ) ;
215- done ( ) ;
216- }
217+ it ( "should return the same sync state as emitted sync events" , async function ( ) {
218+ const syncingPromise = new Promise ( ( resolve ) => {
219+ client . on ( "sync" , function syncListener ( state ) {
220+ expect ( state ) . toEqual ( client . getSyncState ( ) ) ;
221+ if ( state === "SYNCING" ) {
222+ client . removeListener ( "sync" , syncListener ) ;
223+ resolve ( ) ;
224+ }
225+ } ) ;
217226 } ) ;
218- client . startClient ( ) ;
227+ await client . startClient ( ) ;
228+ await syncingPromise ;
219229 } ) ;
220230 } ) ;
221231
@@ -258,8 +268,8 @@ describe("MatrixClient", function() {
258268 } ) ;
259269
260270 describe ( "retryImmediately" , function ( ) {
261- it ( "should return false if there is no request waiting" , function ( ) {
262- client . startClient ( ) ;
271+ it ( "should return false if there is no request waiting" , async function ( ) {
272+ await client . startClient ( ) ;
263273 expect ( client . retryImmediately ( ) ) . toBe ( false ) ;
264274 } ) ;
265275
0 commit comments