Skip to content

Commit f162214

Browse files
committed
remove enzyme & address test warnings
1 parent b147782 commit f162214

File tree

10 files changed

+142
-310
lines changed

10 files changed

+142
-310
lines changed

before-tests.js

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,34 @@
11
/* eslint-env node */
22

33
import 'url-search-params-polyfill';
4+
5+
// Suppress act() warnings only for async markdown rendering (SyncMarkdownView /
6+
// QuickStartMarkdownView). Other act warnings still surface so new tests stay honest.
7+
const originalError = console.error;
8+
9+
const isMarkdownActWarning = (...args) => {
10+
const message = args
11+
.map((a) => {
12+
if (typeof a === 'string') {
13+
return a;
14+
}
15+
if (a instanceof Error && typeof a.message === 'string') {
16+
return a.message;
17+
}
18+
return '';
19+
})
20+
.join('\n');
21+
if (!message.includes('was not wrapped in act(')) {
22+
return false;
23+
}
24+
return (
25+
message.includes('SyncMarkdownView') || message.includes('QuickStartMarkdownView')
26+
);
27+
};
28+
29+
console.error = (...args) => {
30+
if (isMarkdownActWarning(...args)) {
31+
return;
32+
}
33+
originalError.call(console, ...args);
34+
};

packages/module/package.json

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -69,18 +69,13 @@
6969
"@testing-library/jest-dom": "^6.9.1",
7070
"@testing-library/react": "^13.4.0",
7171
"@types/dompurify": "^3.0.5",
72-
"@types/enzyme": "^3.10.7",
73-
"@types/enzyme-adapter-react-16": "^1.0.6",
7472
"@types/history": "^4.7.8",
7573
"@types/node": "^14.14.35",
7674
"@types/react": "^18.2.79",
7775
"@types/react-dom": "^18.0.0",
7876
"clean-css-cli": "^4.3.0",
7977
"concat-files": "^0.1.1",
8078
"dart-sass": "^1.25.0",
81-
"enzyme": "^3.7.0",
82-
"enzyme-adapter-react-16": "^1.15.5",
83-
"enzyme-to-json": "^3.6.1",
8479
"monaco-editor": "0.34.1",
8580
"node-sass-glob-importer": "^5.3.2",
8681
"prettier": "^2.8.8",

packages/module/src/catalog/__tests__/QuickStartCatalog.spec.tsx

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { render, screen } from '@testing-library/react';
1+
import { render, screen, waitFor } from '@testing-library/react';
22
import { getQuickStarts } from '../../data/test-utils';
33
import { QuickStartContext, QuickStartContextDefaults } from '../../utils/quick-start-context';
44
import QuickStartCatalog from '../QuickStartCatalog';
@@ -24,12 +24,16 @@ describe('QuickStartCatalog', () => {
2424
expect(screen.queryByRole('article')).not.toBeInTheDocument();
2525
});
2626

27-
it('should load a gallery if QS exist', () => {
27+
it('should load a gallery if QS exist', async () => {
2828
const quickStarts = getQuickStarts();
2929
renderWithContext({ quickStarts });
3030
// Each tile exposes the quick start display name as the title control (link-styled button)
31-
quickStarts.forEach((qs) => {
32-
expect(screen.getByRole('button', { name: qs.spec.displayName })).toBeInTheDocument();
31+
await waitFor(() => {
32+
quickStarts.forEach((qs) => {
33+
expect(
34+
screen.getByRole('button', { name: qs.spec.displayName }),
35+
).toBeInTheDocument();
36+
});
3337
});
3438
});
3539
});

packages/module/src/catalog/__tests__/QuickStartTile.spec.tsx

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { render, screen } from '@testing-library/react';
1+
import { render, screen, waitFor } from '@testing-library/react';
22
import { getQuickStarts } from '../../data/test-utils';
33
import { QuickStartStatus } from '../../utils/quick-start-types';
44
import { QuickStartContext, QuickStartContextDefaults } from '../../utils/quick-start-context';
@@ -21,28 +21,36 @@ const renderWithContext = (props: any) =>
2121
);
2222

2323
describe('QuickStartTile', () => {
24-
it('should load proper catalog tile without featured property', () => {
24+
it('should load proper catalog tile without featured property', async () => {
2525
const quickStart = quickstarts[0];
2626
renderWithContext({
2727
quickStart,
2828
status: QuickStartStatus.NOT_STARTED,
2929
onClick: jest.fn(),
3030
isActive: false,
3131
});
32-
expect(screen.getByRole('button', { name: quickStart.spec.displayName })).toBeInTheDocument();
32+
await waitFor(() => {
33+
expect(
34+
screen.getByRole('button', { name: quickStart.spec.displayName }),
35+
).toBeInTheDocument();
36+
});
3337
// Status label is omitted for not-started tiles
3438
expect(screen.queryByText('In progress')).not.toBeInTheDocument();
3539
});
3640

37-
it('should load proper catalog tile with featured property', () => {
41+
it('should load proper catalog tile with featured property', async () => {
3842
const quickStart = quickstarts[1];
3943
renderWithContext({
4044
quickStart,
4145
status: QuickStartStatus.IN_PROGRESS,
4246
onClick: jest.fn(),
4347
isActive: true,
4448
});
45-
expect(screen.getByRole('button', { name: quickStart.spec.displayName })).toBeInTheDocument();
49+
await waitFor(() => {
50+
expect(
51+
screen.getByRole('button', { name: quickStart.spec.displayName }),
52+
).toBeInTheDocument();
53+
});
4654
expect(screen.getByText('In progress')).toBeInTheDocument();
4755
});
4856
});

packages/module/src/catalog/__tests__/QuickStartTileDescription.spec.tsx

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { render, screen } from '@testing-library/react';
1+
import { render, screen, waitFor } from '@testing-library/react';
22
import { getQuickStarts } from '../../data/test-utils';
33
import { QuickStartContext, QuickStartContextDefaults } from '../../utils/quick-start-context';
44
import QuickStartTileDescription from '../QuickStartTileDescription';
@@ -19,18 +19,26 @@ const renderWithContext = (props: any) =>
1919
);
2020

2121
describe('QuickStartTileDescription', () => {
22-
it('should show prerequisites only if provided', () => {
22+
it('should show prerequisites only if provided', async () => {
2323
const quickStart = getQuickStarts()[0].spec;
2424
renderWithContext({ description: quickStart.description });
25-
expect(screen.queryByRole('button', { name: 'Show prerequisites' })).not.toBeInTheDocument();
25+
await waitFor(() => {
26+
expect(
27+
screen.queryByRole('button', { name: 'Show prerequisites' }),
28+
).not.toBeInTheDocument();
29+
});
2630
});
2731

28-
it('should render prerequisites trigger when prerequisite list is non-empty', () => {
32+
it('should render prerequisites trigger when prerequisite list is non-empty', async () => {
2933
const quickStart = getQuickStarts()[2].spec;
3034
renderWithContext({
3135
description: quickStart.description,
3236
prerequisites: quickStart.prerequisites,
3337
});
34-
expect(screen.getByRole('button', { name: 'Show prerequisites' })).toBeInTheDocument();
38+
await waitFor(() => {
39+
expect(
40+
screen.getByRole('button', { name: 'Show prerequisites' }),
41+
).toBeInTheDocument();
42+
});
3543
});
3644
});

packages/module/src/controller/__tests__/QuickStartFooter.spec.tsx

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { render, screen } from '@testing-library/react';
1+
import { render, screen, waitFor } from '@testing-library/react';
22
import { QuickStartStatus } from '../../utils/quick-start-types';
33
import { QuickStartContext, QuickStartContextDefaults } from '../../utils/quick-start-context';
44
import QuickStartFooter from '../QuickStartFooter';
@@ -19,7 +19,7 @@ const renderWithContext = (props: any) =>
1919
);
2020

2121
describe('QuickStartFooter', () => {
22-
it('should load Start button for not started tours', () => {
22+
it('should load Start button for not started tours', async () => {
2323
renderWithContext({
2424
status: QuickStartStatus.NOT_STARTED,
2525
footerClass: 'test',
@@ -29,11 +29,13 @@ describe('QuickStartFooter', () => {
2929
totalTasks: 4,
3030
taskNumber: -1,
3131
});
32-
expect(screen.getByRole('button', { name: 'Start' })).toBeInTheDocument();
32+
await waitFor(() => {
33+
expect(screen.getByRole('button', { name: 'Start' })).toBeInTheDocument();
34+
});
3335
expect(screen.queryByRole('button', { name: 'Back' })).not.toBeInTheDocument();
3436
});
3537

36-
it('should load Continue and Restart buttons for in progress tours at intro page', () => {
38+
it('should load Continue and Restart buttons for in progress tours at intro page', async () => {
3739
renderWithContext({
3840
status: QuickStartStatus.IN_PROGRESS,
3941
footerClass: 'test',
@@ -43,11 +45,13 @@ describe('QuickStartFooter', () => {
4345
totalTasks: 4,
4446
taskNumber: -1,
4547
});
46-
expect(screen.getByRole('button', { name: 'Continue' })).toBeInTheDocument();
48+
await waitFor(() => {
49+
expect(screen.getByRole('button', { name: 'Continue' })).toBeInTheDocument();
50+
});
4751
expect(screen.getByRole('button', { name: 'Restart' })).toBeInTheDocument();
4852
});
4953

50-
it('should load Next, Back, and Restart buttons for in progress tours in task page', () => {
54+
it('should load Next, Back, and Restart buttons for in progress tours in task page', async () => {
5155
renderWithContext({
5256
status: QuickStartStatus.IN_PROGRESS,
5357
footerClass: 'test',
@@ -57,12 +61,14 @@ describe('QuickStartFooter', () => {
5761
totalTasks: 4,
5862
taskNumber: 2,
5963
});
60-
expect(screen.getByRole('button', { name: 'Next' })).toBeInTheDocument();
64+
await waitFor(() => {
65+
expect(screen.getByRole('button', { name: 'Next' })).toBeInTheDocument();
66+
});
6167
expect(screen.getByRole('button', { name: 'Back' })).toBeInTheDocument();
6268
expect(screen.getByRole('button', { name: 'Restart' })).toBeInTheDocument();
6369
});
6470

65-
it('should load Close, Back and Restart buttons for completed tours in conclusion page', () => {
71+
it('should load Close, Back and Restart buttons for completed tours in conclusion page', async () => {
6672
renderWithContext({
6773
status: QuickStartStatus.COMPLETE,
6874
footerClass: 'test',
@@ -72,7 +78,9 @@ describe('QuickStartFooter', () => {
7278
totalTasks: 4,
7379
taskNumber: 4,
7480
});
75-
expect(screen.getByRole('button', { name: 'Close' })).toBeInTheDocument();
81+
await waitFor(() => {
82+
expect(screen.getByRole('button', { name: 'Close' })).toBeInTheDocument();
83+
});
7684
expect(screen.getByRole('button', { name: 'Back' })).toBeInTheDocument();
7785
expect(screen.getByRole('button', { name: 'Restart' })).toBeInTheDocument();
7886
});

packages/module/src/controller/__tests__/QuickStartTaskHeader.spec.tsx

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { render, screen } from '@testing-library/react';
1+
import { render, screen, waitFor } from '@testing-library/react';
22
import { QuickStartTaskStatus } from '../../utils/quick-start-types';
33
import { QuickStartContext, QuickStartContextDefaults } from '../../utils/quick-start-context';
44
import QuickStartTaskHeader from '../QuickStartTaskHeader';
@@ -26,18 +26,22 @@ const renderWithContext = (props = {}) =>
2626
);
2727

2828
describe('QuickStartTaskHeader', () => {
29-
it('should render subtitle for active task', () => {
29+
it('should render subtitle for active task', async () => {
3030
renderWithContext();
31-
expect(
32-
screen.getByRole('button', {
33-
name: new RegExp(`${defaultProps.title}.*${defaultProps.subtitle}`),
34-
}),
35-
).toBeInTheDocument();
31+
await waitFor(() => {
32+
expect(
33+
screen.getByRole('button', {
34+
name: new RegExp(`${defaultProps.title}.*${defaultProps.subtitle}`),
35+
}),
36+
).toBeInTheDocument();
37+
});
3638
});
3739

38-
it('should not render subtitle if task is not active', () => {
40+
it('should not render subtitle if task is not active', async () => {
3941
renderWithContext({ isActiveTask: false });
40-
expect(screen.getByRole('button', { name: defaultProps.title })).toBeInTheDocument();
42+
await waitFor(() => {
43+
expect(screen.getByRole('button', { name: defaultProps.title })).toBeInTheDocument();
44+
});
4145
expect(screen.queryByText(defaultProps.subtitle)).not.toBeInTheDocument();
4246
});
4347
});

packages/module/src/controller/__tests__/QuickStartTaskReview.spec.tsx

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,23 +26,29 @@ const renderWithContext = (props = {}) =>
2626
);
2727

2828
describe('QuickStartTaskReview', () => {
29-
it('should render review prompt with yes/no while task is in review', () => {
29+
it('should render review prompt with yes/no while task is in review', async () => {
3030
renderWithContext();
31-
expect(screen.getByRole('alert')).toBeInTheDocument();
31+
await waitFor(() => {
32+
expect(screen.getByRole('alert')).toBeInTheDocument();
33+
});
3234
expect(screen.getByText('Check your work')).toBeInTheDocument();
3335
expect(screen.getByRole('radio', { name: 'Yes' })).not.toBeChecked();
3436
expect(screen.getByRole('radio', { name: 'No' })).not.toBeChecked();
3537
});
3638

37-
it('should mark Yes selected when task status is success', () => {
39+
it('should mark Yes selected when task status is success', async () => {
3840
renderWithContext({ taskStatus: QuickStartTaskStatus.SUCCESS });
39-
expect(screen.getByRole('radio', { name: 'Yes' })).toBeChecked();
41+
await waitFor(() => {
42+
expect(screen.getByRole('radio', { name: 'Yes' })).toBeChecked();
43+
});
4044
expect(screen.getByRole('radio', { name: 'No' })).not.toBeChecked();
4145
});
4246

4347
it('should mark No selected and show failed-task help when task status is failed', async () => {
4448
renderWithContext({ taskStatus: QuickStartTaskStatus.FAILED });
45-
expect(screen.getByRole('radio', { name: 'No' })).toBeChecked();
49+
await waitFor(() => {
50+
expect(screen.getByRole('radio', { name: 'No' })).toBeChecked();
51+
});
4652
expect(screen.getByRole('radio', { name: 'Yes' })).not.toBeChecked();
4753
await waitFor(() => {
4854
expect(document.body.textContent).toMatch(/This task is incomplete/);

packages/module/src/controller/__tests__/QuickStartTasks.spec.tsx

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { render, screen } from '@testing-library/react';
1+
import { render, screen, waitFor } from '@testing-library/react';
22
import { allQuickStarts } from '../../data/quick-start-test-data';
33
import { QuickStartTaskStatus } from '../../utils/quick-start-types';
44
import { QuickStartContext, QuickStartContextDefaults } from '../../utils/quick-start-context';
@@ -39,14 +39,16 @@ describe('QuickStartTasks', () => {
3939
jest.clearAllMocks();
4040
});
4141

42-
it('should render correct number of tasks based on currentTaskIndex', () => {
42+
it('should render correct number of tasks based on currentTaskIndex', async () => {
4343
renderWithContext();
44-
// Only non-INIT tasks are rendered; first task is SUCCESS so it shows
45-
const taskHeaders = screen.getAllByRole('listitem');
46-
expect(taskHeaders).toHaveLength(1);
44+
await waitFor(() => {
45+
// Only non-INIT tasks are rendered; first task is SUCCESS so it shows
46+
const taskHeaders = screen.getAllByRole('listitem');
47+
expect(taskHeaders).toHaveLength(1);
48+
});
4749
});
4850

49-
it('should render description if a task is active', () => {
51+
it('should render description if a task is active', async () => {
5052
renderWithContext({
5153
allTaskStatuses: [
5254
QuickStartTaskStatus.SUCCESS,
@@ -55,20 +57,24 @@ describe('QuickStartTasks', () => {
5557
],
5658
taskNumber: 2,
5759
});
58-
// All 3 tasks are non-INIT, so all render
59-
const taskHeaders = screen.getAllByRole('listitem');
60-
expect(taskHeaders).toHaveLength(3);
60+
await waitFor(() => {
61+
// All 3 tasks are non-INIT, so all render
62+
const taskHeaders = screen.getAllByRole('listitem');
63+
expect(taskHeaders).toHaveLength(3);
64+
});
6165
});
6266

63-
it('should render review when task is active and in Review state', () => {
67+
it('should render review when task is active and in Review state', async () => {
6468
renderWithContext({
6569
allTaskStatuses: [
6670
QuickStartTaskStatus.SUCCESS,
6771
QuickStartTaskStatus.REVIEW,
6872
QuickStartTaskStatus.INIT,
6973
],
7074
});
71-
// "Check your work" is the alert title for QuickStartTaskReview
72-
expect(screen.getByText('Check your work')).toBeInTheDocument();
75+
await waitFor(() => {
76+
// "Check your work" is the alert title for QuickStartTaskReview
77+
expect(screen.getByText('Check your work')).toBeInTheDocument();
78+
});
7379
});
7480
});

0 commit comments

Comments
 (0)