@@ -159,28 +159,31 @@ describe('atlasSignInReducer', function () {
159159 } ) ;
160160
161161 it ( 'should cancel sign in if sign in is in progress' , async function ( ) {
162- const mockAtlasService = {
163- isAuthenticated : sandbox
164- . stub ( )
165- . callsFake ( ( { signal } : { signal : AbortSignal } ) => {
166- return new Promise ( ( resolve , reject ) => {
167- signal . addEventListener ( 'abort' , ( ) => {
168- reject ( signal . reason ) ;
169- } ) ;
162+ const isAuthenticatedStub = sandbox
163+ . stub ( )
164+ . callsFake ( ( { signal } : { signal : AbortSignal } ) => {
165+ return new Promise ( ( resolve , reject ) => {
166+ signal . addEventListener ( 'abort' , ( ) => {
167+ reject ( signal . reason ) ;
170168 } ) ;
171- } ) ,
169+ } ) ;
170+ } ) ;
171+ const mockAtlasService = {
172+ isAuthenticated : isAuthenticatedStub ,
172173 } ;
173174 const store = configureStore ( {
174175 atlasAuthService : mockAtlasService as any ,
175176 } ) ;
176177
177178 void store . dispatch ( performSignInAttempt ( ) ) . catch ( ( ) => { } ) ;
178179
179- await Promise . all ( [
180- store . dispatch ( signIn ( ) ) ,
181- store . dispatch ( cancelSignIn ( ) ) ,
182- ] ) ;
180+ // Give it some time for start the sign in attempt. It will be waiting
181+ // at isAuthenticated, which never resolves.
182+ await new Promise ( ( resolve ) => setTimeout ( resolve , 100 ) ) ;
183+ store . dispatch ( cancelSignIn ( ) ) ;
183184 expect ( store . getState ( ) ) . to . have . nested . property ( 'state' , 'canceled' ) ;
185+
186+ expect ( isAuthenticatedStub ) . to . have . been . calledOnce ;
184187 } ) ;
185188 } ) ;
186189
0 commit comments