Skip to content

Commit

Permalink
test: finish rendering before makign assertions
Browse files Browse the repository at this point in the history
  • Loading branch information
jamesdh committed Mar 21, 2023
1 parent 08563ee commit cc95b4c
Showing 1 changed file with 48 additions and 38 deletions.
86 changes: 48 additions & 38 deletions src/__tests__/AuthContext.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -97,25 +97,29 @@ describe('AuthContext', () => {
});

it('should generate a UserManager', async () => {
render(
<AuthProvider
authority="http://127.0.0.1"
clientId="client-id-test"
redirectUri="http://127.0.0.1"
/>,
);
await act(async () => {
render(
<AuthProvider
authority="http://127.0.0.1"
clientId="client-id-test"
redirectUri="http://127.0.0.1"
/>,
);
});
expect(UserManager).toHaveBeenCalled();
});

it('should use post-logout redirect URI when given', async () => {
render(
<AuthProvider
authority="http://127.0.0.1"
clientId="client-id-test"
redirectUri="http://127.0.0.1"
postLogoutRedirectUri="https://localhost"
/>,
);
await act(async () => {
render(
<AuthProvider
authority="http://127.0.0.1"
clientId="client-id-test"
redirectUri="http://127.0.0.1"
postLogoutRedirectUri="https://localhost"
/>,
);
});
expect(UserManager).toHaveBeenLastCalledWith(
expect.objectContaining({
post_logout_redirect_uri: 'https://localhost',
Expand All @@ -124,40 +128,46 @@ describe('AuthContext', () => {
});

it('should fall back to redirectUri when post-logout redirect URI is not given', async () => {
render(
<AuthProvider
authority="http://127.0.0.1"
clientId="client-id-test"
redirectUri="http://127.0.0.1"
/>,
);
await act(async () => {
render(
<AuthProvider
authority="http://127.0.0.1"
clientId="client-id-test"
redirectUri="http://127.0.0.1"
/>,
);
});
expect(UserManager).toHaveBeenLastCalledWith(
expect.objectContaining({ post_logout_redirect_uri: 'http://127.0.0.1' }),
);
});

it('should use silent redirect URI when given', async () => {
render(
<AuthProvider
authority="http://127.0.0.1"
clientId="client-id-test"
redirectUri="http://127.0.0.1"
silentRedirectUri="https://localhost"
/>,
);
await act(async () => {
render(
<AuthProvider
authority="http://127.0.0.1"
clientId="client-id-test"
redirectUri="http://127.0.0.1"
silentRedirectUri="https://localhost"
/>,
);
});
expect(UserManager).toHaveBeenLastCalledWith(
expect.objectContaining({ silent_redirect_uri: 'https://localhost' }),
);
});

it('should fall back to redirectUri when silent redirect URI is not given', async () => {
render(
<AuthProvider
authority="http://127.0.0.1"
clientId="client-id-test"
redirectUri="http://127.0.0.1"
/>,
);
await act(async () => {
render(
<AuthProvider
authority="http://127.0.0.1"
clientId="client-id-test"
redirectUri="http://127.0.0.1"
/>,
);
});
expect(UserManager).toHaveBeenLastCalledWith(
expect.objectContaining({ silent_redirect_uri: 'http://127.0.0.1' }),
);
Expand Down Expand Up @@ -367,4 +377,4 @@ describe('AuthContext', () => {
expect(u.events.removeSilentRenewError).toHaveBeenCalledTimes(1);
expect(callbacks).toHaveLength(0);
});
});
});

0 comments on commit cc95b4c

Please sign in to comment.