Skip to content

fix(clerk-js): Fix act output in tests [SDK-1054] #2289

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

Merged
merged 4 commits into from
Dec 7, 2023
Merged
Show file tree
Hide file tree
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
5 changes: 5 additions & 0 deletions .changeset/cold-coins-listen.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@clerk/clerk-js': patch
---

Fixes errant `act` output from unit tests
2 changes: 1 addition & 1 deletion packages/clerk-js/src/core/clerk.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -519,7 +519,7 @@ describe('Clerk singleton', () => {
let logSpy;

beforeEach(() => {
logSpy = jest.spyOn(console, 'log');
logSpy = jest.spyOn(console, 'log').mockReturnValue(void 0);
sut = new Clerk(productionPublishableKey);
});

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import type { MembershipRole, OrganizationInvitationResource } from '@clerk/types';
import { describe } from '@jest/globals';
import { waitFor } from '@testing-library/dom';
import { act } from '@testing-library/react';
import React from 'react';

import { ClerkAPIResponseError } from '../../../../core/resources';
Expand All @@ -15,12 +14,16 @@ describe('InviteMembersPage', () => {
it('renders the component', async () => {
const { wrapper, fixtures } = await createFixtures(f => {
f.withOrganizations();
f.withUser({ email_addresses: ['[email protected]'], organization_memberships: [{ name: 'Org1', role: 'admin' }] });
f.withUser({
email_addresses: ['[email protected]'],
organization_memberships: [{ name: 'Org1', role: 'admin' }],
});
});

fixtures.clerk.organization?.getRoles.mockRejectedValue(null);
const { getByText } = await act(() => render(<InviteMembersPage />, { wrapper }));
expect(getByText('Invite new members to this organization')).toBeDefined();

const { findByText } = render(<InviteMembersPage />, { wrapper });
await waitFor(async () => expect(await findByText('Invite new members to this organization')).toBeInTheDocument());
});

describe('Submitting', () => {
Expand All @@ -42,6 +45,7 @@ describe('InviteMembersPage', () => {

await userEvent.click(getByRole('button', { name: /select an option/i }));
await userEvent.click(getByText(/^member$/i));

expect(getByRole('button', { name: 'Send invitations' })).not.toBeDisabled();
});

Expand All @@ -61,9 +65,12 @@ describe('InviteMembersPage', () => {
await userEvent.click(getByRole('button', { name: 'Select an option' }));
await userEvent.click(getByText('Member'));
await userEvent.click(getByRole('button', { name: 'Send invitations' }));
expect(fixtures.clerk.organization?.inviteMembers).toHaveBeenCalledWith({
emailAddresses: ['[email protected]'],
role: 'basic_member' as MembershipRole,

await waitFor(() => {
expect(fixtures.clerk.organization?.inviteMembers).toHaveBeenCalledWith({
emailAddresses: ['[email protected]'],
role: 'basic_member' as MembershipRole,
});
});
});

Expand Down Expand Up @@ -98,9 +105,12 @@ describe('InviteMembersPage', () => {
await userEvent.click(getByRole('button', { name: 'Select an option' }));
await userEvent.click(getByText('Teacher'));
await userEvent.click(getByRole('button', { name: 'Send invitations' }));
expect(fixtures.clerk.organization?.inviteMembers).toHaveBeenCalledWith({
emailAddresses: ['[email protected]'],
role: 'org:teacher' as MembershipRole,

await waitFor(() => {
expect(fixtures.clerk.organization?.inviteMembers).toHaveBeenCalledWith({
emailAddresses: ['[email protected]'],
role: 'org:teacher' as MembershipRole,
});
});
});

Expand All @@ -123,9 +133,12 @@ describe('InviteMembersPage', () => {
await userEvent.click(getByRole('button', { name: 'Select an option' }));
await userEvent.click(getByText('Member'));
await userEvent.click(getByRole('button', { name: 'Send invitations' }));
expect(fixtures.clerk.organization?.inviteMembers).toHaveBeenCalledWith({
emailAddresses: ['[email protected]', '[email protected]', '[email protected]', '[email protected]'],
role: 'basic_member' as MembershipRole,

await waitFor(() => {
expect(fixtures.clerk.organization?.inviteMembers).toHaveBeenCalledWith({
emailAddresses: ['[email protected]', '[email protected]', '[email protected]', '[email protected]'],
role: 'basic_member' as MembershipRole,
});
});
});

Expand All @@ -145,9 +158,11 @@ describe('InviteMembersPage', () => {
await userEvent.click(getByRole('button', { name: 'Select an option' }));
await userEvent.click(getByText('Admin'));
await userEvent.click(getByRole('button', { name: 'Send invitations' }));
expect(fixtures.clerk.organization?.inviteMembers).toHaveBeenCalledWith({
emailAddresses: ['[email protected]'],
role: 'admin' as MembershipRole,
await waitFor(() => {
expect(fixtures.clerk.organization?.inviteMembers).toHaveBeenCalledWith({
emailAddresses: ['[email protected]'],
role: 'admin' as MembershipRole,
});
});
});

Expand Down
Loading