@@ -159,28 +159,31 @@ describe('atlasSignInReducer', function () {
159
159
} ) ;
160
160
161
161
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 ) ;
170
168
} ) ;
171
- } ) ,
169
+ } ) ;
170
+ } ) ;
171
+ const mockAtlasService = {
172
+ isAuthenticated : isAuthenticatedStub ,
172
173
} ;
173
174
const store = configureStore ( {
174
175
atlasAuthService : mockAtlasService as any ,
175
176
} ) ;
176
177
177
178
void store . dispatch ( performSignInAttempt ( ) ) . catch ( ( ) => { } ) ;
178
179
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 ( ) ) ;
183
184
expect ( store . getState ( ) ) . to . have . nested . property ( 'state' , 'canceled' ) ;
185
+
186
+ expect ( isAuthenticatedStub ) . to . have . been . calledOnce ;
184
187
} ) ;
185
188
} ) ;
186
189
0 commit comments