Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 16 additions & 13 deletions packages/atlas-service/src/store/atlas-signin-reducer.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -159,28 +159,31 @@ describe('atlasSignInReducer', function () {
});

it('should cancel sign in if sign in is in progress', async function () {
const mockAtlasService = {
isAuthenticated: sandbox
.stub()
.callsFake(({ signal }: { signal: AbortSignal }) => {
return new Promise((resolve, reject) => {
signal.addEventListener('abort', () => {
reject(signal.reason);
});
const isAuthenticatedStub = sandbox
.stub()
.callsFake(({ signal }: { signal: AbortSignal }) => {
return new Promise((resolve, reject) => {
signal.addEventListener('abort', () => {
reject(signal.reason);
});
}),
});
});
const mockAtlasService = {
isAuthenticated: isAuthenticatedStub,
};
const store = configureStore({
atlasAuthService: mockAtlasService as any,
});

void store.dispatch(performSignInAttempt()).catch(() => {});

await Promise.all([
store.dispatch(signIn()),
store.dispatch(cancelSignIn()),
]);
Comment on lines -179 to -182
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We are already attempting signin in performSignInAttempt and doing it here, triggers isAuthenticated stub and hence rejecting the promise after the test has finished with its assertions.

So I removed extra signin and also ensured that isAuthenticated is only called once.

// Give it some time for start the sign in attempt. It will be waiting
// at isAuthenticated, which never resolves.
await new Promise((resolve) => setTimeout(resolve, 100));
store.dispatch(cancelSignIn());
expect(store.getState()).to.have.nested.property('state', 'canceled');

expect(isAuthenticatedStub).to.have.been.calledOnce;
});
});

Expand Down
Loading