-
Notifications
You must be signed in to change notification settings - Fork 80
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Service stop should not be called #233
Conversation
9853c75
to
bf4fe03
Compare
@@ -70,6 +70,8 @@ describe('<LoginCallback />', () => { | |||
</Security> | |||
); | |||
expect(oktaAuth.handleLoginRedirect).toHaveBeenCalledTimes(1); | |||
await Promise.resolve(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What is the purpose of this Promise.resolve
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To wait for handleLoginRedirect
which is a promise
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can put the await in the expect call
expect(await oktaAuth.handleLoginRedirect)
or
await expect(oktaAuth.handleLoginRedirect).resolves.toHaveBeenCalled()
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
handleLoginRedirect
should be called inside useEffect
of <LoginCallback />
Previous implementation included excess start()
after promise resolves:
oktaAuth.handleLoginRedirect().then(() => {
oktaAuth.start() // not needed
})
In this test we need to wait for handleLoginRedirect
to be called implicitly inside useEffect
and resolved, then check start()
was not called.
Awaiting it explicitly in test would not work
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
await act(async () => {
mount(
<Security {...mockProps}>
<LoginCallback />
</Security>
);
});
this works without need of await Promise.resolve();
Changes:
oktaAuth.stop()
from<Security>
oktaAuth.start()
from<LoginCallback>
afterhandleLoginRedirect
- not neededuseEffect
hook in<Security>
- don't watch forrestoreOriginalUri
prop to perform side-effects (start, subscribe, unsubscribe) on oktaAuthokta-auth-js
to latestInternal ref: OKTA-492710 (including deps OKTA-482712 OKTA-482710)