@@ -23,6 +23,7 @@ import ReactDOM from 'react-dom';
2323import ReactTestUtils from 'react-addons-test-utils' ;
2424import expect from 'expect' ;
2525import q from 'q' ;
26+ import MatrixReactTestUtils from 'matrix-react-test-utils' ;
2627
2728import jssdk from 'matrix-js-sdk' ;
2829
@@ -183,11 +184,8 @@ describe('loading:', function () {
183184 return httpBackend . flush ( ) ;
184185 } ) . then ( ( ) => {
185186 // Wait for another trip around the event loop for the UI to update
186- return q . delay ( 10 ) ;
187+ return awaitLoginComponent ( matrixChat ) ;
187188 } ) . then ( ( ) => {
188- // we expect a single <Login> component following session load
189- ReactTestUtils . findRenderedComponentWithType (
190- matrixChat , sdk . getComponent ( 'structures.login.Login' ) ) ;
191189 expect ( windowLocation . hash ) . toEqual ( "#/login" ) ;
192190 } ) . done ( done , done ) ;
193191 } ) ;
@@ -232,7 +230,7 @@ describe('loading:', function () {
232230 uriFragment : "#/login" ,
233231 } ) ;
234232
235- return q . delay ( 100 ) . then ( ( ) => {
233+ return awaitLoginComponent ( matrixChat ) . then ( ( ) => {
236234 // we expect a single <Login> component
237235 ReactTestUtils . findRenderedComponentWithType (
238236 matrixChat , sdk . getComponent ( 'structures.login.Login' ) ) ;
@@ -366,7 +364,7 @@ describe('loading:', function () {
366364 } ) ;
367365
368366 // give the UI a chance to display
369- return q . delay ( 50 ) ;
367+ return awaitLoginComponent ( matrixChat ) ;
370368 } ) ;
371369
372370 it ( 'shows a login view' , function ( ) {
@@ -530,7 +528,7 @@ describe('loading:', function () {
530528
531529 dis . dispatch ( { action : 'start_login' } ) ;
532530
533- return q . delay ( 1 ) ;
531+ return awaitLoginComponent ( matrixChat ) ;
534532 } ) ;
535533 } ) ;
536534
@@ -607,7 +605,6 @@ describe('loading:', function () {
607605 } ) ;
608606 } ) ;
609607
610-
611608 // check that we have a Login component, send a 'user:pass' login,
612609 // and await the HTTP requests.
613610 function completeLogin ( matrixChat ) {
@@ -723,3 +720,9 @@ function awaitRoomView(matrixChat, retryLimit, retryCount) {
723720 matrixChat , sdk . getComponent ( 'structures.RoomView' ) ) ;
724721 return q ( ) ;
725722}
723+
724+ function awaitLoginComponent ( matrixChat , attempts ) {
725+ return MatrixReactTestUtils . waitForRenderedComponentWithType (
726+ matrixChat , sdk . getComponent ( 'structures.login.Login' ) , attempts ,
727+ ) ;
728+ }
0 commit comments