Skip to content

Commit

Permalink
test: Fix testing-library/no-wait-for-multiple-assertions violations
Browse files Browse the repository at this point in the history
  • Loading branch information
ryan953 committed Dec 31, 2024
1 parent d45e77e commit 11aee76
Show file tree
Hide file tree
Showing 31 changed files with 224 additions and 228 deletions.
1 change: 0 additions & 1 deletion eslint.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -965,7 +965,6 @@ export default typescript.config([
'testing-library/no-container': 'warn', // TODO(ryan953): Fix the violations, then delete this line
'testing-library/no-node-access': 'warn', // TODO(ryan953): Fix the violations, then delete this line
'testing-library/no-render-in-lifecycle': 'warn', // TODO(ryan953): Fix the violations, then delete this line
'testing-library/no-wait-for-multiple-assertions': 'warn', // TODO(ryan953): Fix the violations, then delete this line
'testing-library/prefer-presence-queries': 'warn', // TODO(ryan953): Fix the violations, then delete this line
'testing-library/prefer-query-by-disappearance': 'warn', // TODO(ryan953): Fix the violations, then delete this line
'testing-library/prefer-screen-queries': 'warn', // TODO(ryan953): Fix the violations, then delete this line
Expand Down
2 changes: 1 addition & 1 deletion static/app/components/contextPickerModal.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -103,8 +103,8 @@ describe('ContextPickerModal', function () {

await waitFor(() => {
expect(fetchProjectsForOrg).toHaveBeenCalled();
expect(onFinish).toHaveBeenLastCalledWith('/test/org2/path/project2/');
});
expect(onFinish).toHaveBeenLastCalledWith('/test/org2/path/project2/');
});

it('selects an org and calls `onFinish` with URL with organization slug', async function () {
Expand Down
2 changes: 1 addition & 1 deletion static/app/components/events/autofix/autofixDiff.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -125,8 +125,8 @@ describe('AutofixDiff', function () {

await waitFor(() => {
expect(screen.queryByTestId('line-added')).not.toBeInTheDocument();
expect(screen.queryByTestId('line-removed')).not.toBeInTheDocument();
});
expect(screen.queryByTestId('line-removed')).not.toBeInTheDocument();
});

it('shows error message on failed edit', async function () {
Expand Down
2 changes: 1 addition & 1 deletion static/app/components/events/eventAttachments.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ describe('EventAttachments', function () {
// Should make the delete request and remove the attachment optimistically
await waitFor(() => {
expect(deleteMock).toHaveBeenCalled();
expect(screen.queryByTestId('pic_1.png')).not.toBeInTheDocument();
});
expect(screen.queryByTestId('pic_1.png')).not.toBeInTheDocument();
});
});
20 changes: 10 additions & 10 deletions static/app/components/group/groupSummary.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -54,12 +54,12 @@ describe('GroupSummary', function () {

await waitFor(() => {
expect(screen.getByText("What's wrong")).toBeInTheDocument();
expect(screen.getByText('Test whats wrong')).toBeInTheDocument();
expect(screen.getByText('In the trace')).toBeInTheDocument();
expect(screen.getByText('Test trace')).toBeInTheDocument();
expect(screen.getByText('Possible cause')).toBeInTheDocument();
expect(screen.getByText('Test possible cause')).toBeInTheDocument();
});
expect(screen.getByText('Test whats wrong')).toBeInTheDocument();
expect(screen.getByText('In the trace')).toBeInTheDocument();
expect(screen.getByText('Test trace')).toBeInTheDocument();
expect(screen.getByText('Possible cause')).toBeInTheDocument();
expect(screen.getByText('Test possible cause')).toBeInTheDocument();
});

it('shows loading state', function () {
Expand Down Expand Up @@ -110,11 +110,11 @@ describe('GroupSummary', function () {

await waitFor(() => {
expect(screen.getByText("What's wrong")).toBeInTheDocument();
expect(screen.getByText('Test whats wrong')).toBeInTheDocument();
expect(screen.queryByText('In the trace')).not.toBeInTheDocument();
expect(screen.getByText('Possible cause')).toBeInTheDocument();
expect(screen.getByText('Test possible cause')).toBeInTheDocument();
});
expect(screen.getByText('Test whats wrong')).toBeInTheDocument();
expect(screen.queryByText('In the trace')).not.toBeInTheDocument();
expect(screen.getByText('Possible cause')).toBeInTheDocument();
expect(screen.getByText('Test possible cause')).toBeInTheDocument();
});

it('renders in preview mode', async function () {
Expand All @@ -131,7 +131,7 @@ describe('GroupSummary', function () {

await waitFor(() => {
expect(screen.getByText("What's wrong")).toBeInTheDocument();
expect(screen.getByText('Test whats wrong')).toBeInTheDocument();
});
expect(screen.getByText('Test whats wrong')).toBeInTheDocument();
});
});
4 changes: 2 additions & 2 deletions static/app/components/group/tagFacets/index.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -139,9 +139,9 @@ describe('Tag Facets', function () {
);
await waitFor(() => {
expect(screen.getByRole('listitem', {name: 'os'})).toBeInTheDocument();
expect(screen.getByRole('listitem', {name: 'device'})).toBeInTheDocument();
expect(screen.getByRole('listitem', {name: 'release'})).toBeInTheDocument();
});
expect(screen.getByRole('listitem', {name: 'device'})).toBeInTheDocument();
expect(screen.getByRole('listitem', {name: 'release'})).toBeInTheDocument();
});

it('expands first tag distribution by default', async function () {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -225,9 +225,9 @@ describe('PageFiltersContainer', function () {

await waitFor(() => {
expect(globalActions.updateDateTime).not.toHaveBeenCalled();
expect(globalActions.updateProjects).not.toHaveBeenCalled();
expect(globalActions.updateEnvironments).not.toHaveBeenCalled();
});
expect(globalActions.updateProjects).not.toHaveBeenCalled();
expect(globalActions.updateEnvironments).not.toHaveBeenCalled();

expect(PageFiltersStore.getState()).toEqual({
isReady: true,
Expand Down
4 changes: 2 additions & 2 deletions static/app/components/search/sources/apiSource.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -398,8 +398,8 @@ describe('ApiSource', function () {
// The return values here are because of fuzzy search matching.
// There are no members that match
expect(mock.mock.calls[1][0].results).toHaveLength(6);
expect(mock.mock.calls[1][0].results[0].item.model.slug).toBe('foo-org');
});
expect(mock.mock.calls[1][0].results[0].item.model.slug).toBe('foo-org');

mock.mockClear();

Expand All @@ -412,8 +412,8 @@ describe('ApiSource', function () {
await waitFor(() => {
// Still have 4 results, but is re-ordered
expect(mock.mock.calls[0][0].results).toHaveLength(6);
expect(mock.mock.calls[0][0].results[0].item.model.slug).toBe('foo-team');
});
expect(mock.mock.calls[0][0].results[0].item.model.slug).toBe('foo-team');
});

describe('API queries', function () {
Expand Down
10 changes: 5 additions & 5 deletions static/app/components/searchQueryBuilder/index.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -163,18 +163,18 @@ describe('SearchQueryBuilder', function () {
// Should call onChange and onSearch after enter
await waitFor(() => {
expect(mockOnChange).toHaveBeenCalledTimes(1);
expect(mockOnChange).toHaveBeenCalledWith('ab', expectedQueryState);
expect(mockOnSearch).toHaveBeenCalledTimes(1);
expect(mockOnSearch).toHaveBeenCalledWith('ab', expectedQueryState);
});
expect(mockOnChange).toHaveBeenCalledWith('ab', expectedQueryState);
expect(mockOnSearch).toHaveBeenCalledTimes(1);
expect(mockOnSearch).toHaveBeenCalledWith('ab', expectedQueryState);

await userEvent.click(document.body);

// Clicking outside activates onBlur
await waitFor(() => {
expect(mockOnBlur).toHaveBeenCalledTimes(1);
expect(mockOnBlur).toHaveBeenCalledWith('ab', expectedQueryState);
});
expect(mockOnBlur).toHaveBeenCalledWith('ab', expectedQueryState);
});
});

Expand All @@ -194,8 +194,8 @@ describe('SearchQueryBuilder', function () {

await waitFor(() => {
expect(mockOnChange).toHaveBeenCalledWith('', expect.anything());
expect(mockOnSearch).toHaveBeenCalledWith('', expect.anything());
});
expect(mockOnSearch).toHaveBeenCalledWith('', expect.anything());

expect(
screen.queryByRole('row', {name: 'browser.name:firefox'})
Expand Down
2 changes: 1 addition & 1 deletion static/app/utils/useDispatchingReducer.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,8 @@ describe('useDispatchingReducer', () => {

await waitFor(() => {
expect(reducer).toHaveBeenCalledTimes(1);
expect(result.current[0]).toEqual({type: 'action'});
});
expect(result.current[0]).toEqual({type: 'action'});
});
it('calls before action with state and action args', () => {
const initialState = {type: 'initial'};
Expand Down
16 changes: 8 additions & 8 deletions static/app/utils/useProjectSdkNeedsUpdate.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,9 @@ describe('useProjectSdkNeedsUpdate', () => {

await waitFor(() => {
expect(result.current.isError).toBeFalsy();
expect(result.current.isFetching).toBeFalsy();
expect(result.current.needsUpdate).toBeFalsy();
});
expect(result.current.isFetching).toBeFalsy();
expect(result.current.needsUpdate).toBeFalsy();
});

it('should be updated it the sdk version is too low', async () => {
Expand All @@ -77,9 +77,9 @@ describe('useProjectSdkNeedsUpdate', () => {
});
await waitFor(() => {
expect(result.current.isError).toBeFalsy();
expect(result.current.isFetching).toBeFalsy();
expect(result.current.needsUpdate).toBeTruthy();
});
expect(result.current.isFetching).toBeFalsy();
expect(result.current.needsUpdate).toBeTruthy();
});

it('should return needsUpdate if multiple projects', async () => {
Expand All @@ -105,9 +105,9 @@ describe('useProjectSdkNeedsUpdate', () => {

await waitFor(() => {
expect(result.current.isError).toBeFalsy();
expect(result.current.isFetching).toBeFalsy();
expect(result.current.needsUpdate).toBeTruthy();
});
expect(result.current.isFetching).toBeFalsy();
expect(result.current.needsUpdate).toBeTruthy();
});

it('should not return needsUpdate if some projects meet minSdk', async () => {
Expand All @@ -133,8 +133,8 @@ describe('useProjectSdkNeedsUpdate', () => {

await waitFor(() => {
expect(result.current.isError).toBeFalsy();
expect(result.current.isFetching).toBeFalsy();
expect(result.current.needsUpdate).toBeFalsy();
});
expect(result.current.isFetching).toBeFalsy();
expect(result.current.needsUpdate).toBeFalsy();
});
});
2 changes: 1 addition & 1 deletion static/app/views/dashboards/dashboard.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -295,8 +295,8 @@ describe('Dashboards > Dashboard', () => {
await userEvent.click(await screen.findByText(/Switch to Transactions/));
await waitFor(() => {
expect(mockOnUpdate).toHaveBeenCalled();
expect(mockHandleUpdateWidgetList).toHaveBeenCalled();
});
expect(mockHandleUpdateWidgetList).toHaveBeenCalled();
});

it('handles duplicate widget in view mode', async () => {
Expand Down
48 changes: 24 additions & 24 deletions static/app/views/dashboards/detail.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -1739,15 +1739,15 @@ describe('Dashboards > Detail', function () {

await waitFor(() => {
expect(mockPUT).toHaveBeenCalledTimes(1);
expect(mockPUT).toHaveBeenCalledWith(
'/organizations/org-slug/dashboards/1/',
expect.objectContaining({
data: expect.objectContaining({
permissions: {isEditableByEveryone: false, teamsWithEditAccess: []},
}),
})
);
});
expect(mockPUT).toHaveBeenCalledWith(
'/organizations/org-slug/dashboards/1/',
expect.objectContaining({
data: expect.objectContaining({
permissions: {isEditableByEveryone: false, teamsWithEditAccess: []},
}),
})
);
});

it('creator can update permissions for dashboard', async function () {
Expand Down Expand Up @@ -1807,15 +1807,15 @@ describe('Dashboards > Detail', function () {

await waitFor(() => {
expect(mockPUT).toHaveBeenCalledTimes(1);
expect(mockPUT).toHaveBeenCalledWith(
'/organizations/org-slug/dashboards/1/',
expect.objectContaining({
data: expect.objectContaining({
permissions: {isEditableByEveryone: true, teamsWithEditAccess: []},
}),
})
);
});
expect(mockPUT).toHaveBeenCalledWith(
'/organizations/org-slug/dashboards/1/',
expect.objectContaining({
data: expect.objectContaining({
permissions: {isEditableByEveryone: true, teamsWithEditAccess: []},
}),
})
);
});

it('creator can update permissions with teams for dashboard', async function () {
Expand Down Expand Up @@ -1891,15 +1891,15 @@ describe('Dashboards > Detail', function () {

await waitFor(() => {
expect(mockPUT).toHaveBeenCalledTimes(1);
expect(mockPUT).toHaveBeenCalledWith(
'/organizations/org-slug/dashboards/1/',
expect.objectContaining({
data: expect.objectContaining({
permissions: {isEditableByEveryone: false, teamsWithEditAccess: [1, 2]},
}),
})
);
});
expect(mockPUT).toHaveBeenCalledWith(
'/organizations/org-slug/dashboards/1/',
expect.objectContaining({
data: expect.objectContaining({
permissions: {isEditableByEveryone: false, teamsWithEditAccess: [1, 2]},
}),
})
);
});

it('disables edit dashboard and add widget button if user cannot edit dashboard', async function () {
Expand Down
8 changes: 4 additions & 4 deletions static/app/views/dashboards/manage/dashboardGrid.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -201,8 +201,8 @@ describe('Dashboards - DashboardGrid', function () {

await waitFor(() => {
expect(deleteMock).toHaveBeenCalled();
expect(dashboardUpdateMock).toHaveBeenCalled();
});
expect(dashboardUpdateMock).toHaveBeenCalled();
});

it('cannot delete last dashboard', async function () {
Expand Down Expand Up @@ -257,8 +257,8 @@ describe('Dashboards - DashboardGrid', function () {

await waitFor(() => {
expect(createMock).toHaveBeenCalled();
expect(dashboardUpdateMock).toHaveBeenCalled();
});
expect(dashboardUpdateMock).toHaveBeenCalled();
});

it('does not throw an error if the POST fails during duplication', async function () {
Expand Down Expand Up @@ -291,9 +291,9 @@ describe('Dashboards - DashboardGrid', function () {

await waitFor(() => {
expect(postMock).toHaveBeenCalled();
// Should not update, and not throw error
expect(dashboardUpdateMock).not.toHaveBeenCalled();
});
// Should not update, and not throw error
expect(dashboardUpdateMock).not.toHaveBeenCalled();
});

it('renders favorite and unfavorite buttons on cards', function () {
Expand Down
8 changes: 4 additions & 4 deletions static/app/views/dashboards/manage/dashboardTable.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -201,8 +201,8 @@ describe('Dashboards - DashboardTable', function () {

await waitFor(() => {
expect(deleteMock).toHaveBeenCalled();
expect(dashboardUpdateMock).toHaveBeenCalled();
});
expect(dashboardUpdateMock).toHaveBeenCalled();
});

it('cannot delete last dashboard', function () {
Expand Down Expand Up @@ -251,8 +251,8 @@ describe('Dashboards - DashboardTable', function () {

await waitFor(() => {
expect(createMock).toHaveBeenCalled();
expect(dashboardUpdateMock).toHaveBeenCalled();
});
expect(dashboardUpdateMock).toHaveBeenCalled();
});

it('does not throw an error if the POST fails during duplication', async function () {
Expand Down Expand Up @@ -282,9 +282,9 @@ describe('Dashboards - DashboardTable', function () {

await waitFor(() => {
expect(postMock).toHaveBeenCalled();
// Should not update, and not throw error
expect(dashboardUpdateMock).not.toHaveBeenCalled();
});
// Should not update, and not throw error
expect(dashboardUpdateMock).not.toHaveBeenCalled();
});

it('renders access column', async function () {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -200,9 +200,9 @@ describe('NewWidgetBuiler', function () {
// see if alias field and add button are not there
await waitFor(() => {
expect(screen.queryByPlaceholderText('Legend Alias')).not.toBeInTheDocument();
expect(screen.queryByText('Add Filter')).not.toBeInTheDocument();
expect(screen.queryByLabelText('Remove this filter')).not.toBeInTheDocument();
});
expect(screen.queryByText('Add Filter')).not.toBeInTheDocument();
expect(screen.queryByLabelText('Remove this filter')).not.toBeInTheDocument();
});

it('renders the group by field on chart widgets', async function () {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -197,9 +197,9 @@ describe('WidgetBuilderSlideout', () => {

await waitFor(() => {
expect(screen.queryByRole('dialog')).not.toBeInTheDocument();
expect(
screen.queryByText('You have unsaved changes. Are you sure you want to leave?')
).not.toBeInTheDocument();
});
expect(
screen.queryByText('You have unsaved changes. Are you sure you want to leave?')
).not.toBeInTheDocument();
});
});
Loading

0 comments on commit 11aee76

Please sign in to comment.