Skip to content

Commit c6c3b72

Browse files
committed
Add unit tests for invalidation hooks
1 parent 33446b8 commit c6c3b72

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

packages/clerk-js/src/core/__tests__/clerk.test.ts

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -535,6 +535,32 @@ describe('Clerk singleton', () => {
535535
expect(mockSession.touch).toHaveBeenCalled();
536536
});
537537

538+
it('does not call __unstable__onBeforeSetActive before session.touch', async () => {
539+
mockSession.touch.mockReturnValueOnce(Promise.resolve());
540+
mockClientFetch.mockReturnValue(Promise.resolve({ signedInSessions: [mockSession] }));
541+
542+
const onBeforeSetActive = jest.fn();
543+
(window as any).__unstable__onBeforeSetActive = onBeforeSetActive;
544+
545+
const sut = new Clerk(productionPublishableKey);
546+
await sut.load();
547+
await sut.setActive({ session: mockSession as any as ActiveSessionResource });
548+
expect(onBeforeSetActive).not.toHaveBeenCalled();
549+
});
550+
551+
it('does not call __unstable__onAfterSetActive after session.touch', async () => {
552+
mockSession.touch.mockReturnValueOnce(Promise.resolve());
553+
mockClientFetch.mockReturnValue(Promise.resolve({ signedInSessions: [mockSession] }));
554+
555+
const onAfterSetActive = jest.fn();
556+
(window as any).__unstable__onAfterSetActive = onAfterSetActive;
557+
558+
const sut = new Clerk(productionPublishableKey);
559+
await sut.load();
560+
await sut.setActive({ session: mockSession as any as ActiveSessionResource });
561+
expect(onAfterSetActive).not.toHaveBeenCalled();
562+
});
563+
538564
it('navigate to `taskUrl` option', async () => {
539565
mockSession.touch.mockReturnValue(Promise.resolve());
540566
mockClientFetch.mockReturnValue(Promise.resolve({ signedInSessions: [mockSession] }));

0 commit comments

Comments
 (0)