diff --git a/Composer/packages/adaptive-form/src/components/__tests__/LoadingTimeout.test.tsx b/Composer/packages/adaptive-form/src/components/__tests__/LoadingTimeout.test.tsx
index 83ed0f608a..8a687f2f16 100644
--- a/Composer/packages/adaptive-form/src/components/__tests__/LoadingTimeout.test.tsx
+++ b/Composer/packages/adaptive-form/src/components/__tests__/LoadingTimeout.test.tsx
@@ -18,9 +18,13 @@ function renderSubject(overrides = {}) {
}
describe('', () => {
- beforeEach(() => {
+ beforeAll(() => {
jest.useFakeTimers();
});
+ afterAll(() => {
+ jest.runOnlyPendingTimers();
+ jest.useRealTimers();
+ });
it('renders a spinner with "Loading"', () => {
const { container } = renderSubject();
diff --git a/Composer/packages/client/__tests__/components/BotRuntimeController/publish-luis-modal.test.tsx b/Composer/packages/client/__tests__/components/BotRuntimeController/publish-luis-modal.test.tsx
index a14e54be36..623a972699 100644
--- a/Composer/packages/client/__tests__/components/BotRuntimeController/publish-luis-modal.test.tsx
+++ b/Composer/packages/client/__tests__/components/BotRuntimeController/publish-luis-modal.test.tsx
@@ -6,7 +6,14 @@ import { fireEvent } from '@botframework-composer/test-utils';
import { PublishDialog } from '../../../src/components/BotRuntimeController/publishDialog';
import { botDisplayNameState, settingsState, dispatcherState, currentProjectIdState } from '../../../src/recoilModel';
import { renderWithRecoil } from '../../testUtils';
-jest.useFakeTimers();
+
+beforeAll(() => {
+ jest.useFakeTimers();
+});
+afterAll(() => {
+ jest.runOnlyPendingTimers();
+ jest.useRealTimers();
+});
const projectId = '12abvc.as324';
const luisConfig = {
diff --git a/Composer/packages/client/__tests__/components/MultiLanguage/MultiLanguage.test.tsx b/Composer/packages/client/__tests__/components/MultiLanguage/MultiLanguage.test.tsx
index f14eef616d..02dd0e9fc5 100644
--- a/Composer/packages/client/__tests__/components/MultiLanguage/MultiLanguage.test.tsx
+++ b/Composer/packages/client/__tests__/components/MultiLanguage/MultiLanguage.test.tsx
@@ -9,9 +9,17 @@ import { AddLanguageModal, DeleteLanguageModal } from '../../../src/components/M
const defaultLanguage = 'en-us';
const languages = ['en-us', 'zh-cn'];
const locale = 'zh-cn';
+
+beforeAll(() => {
+ jest.useFakeTimers();
+});
+afterAll(() => {
+ jest.runOnlyPendingTimers();
+ jest.useRealTimers();
+});
+
describe('', () => {
it('should render the AddLanguageModal form, and do add language', () => {
- jest.useFakeTimers();
const onSubmit = jest.fn(() => {});
const onDismiss = jest.fn(() => {});
const { getByText } = render(
@@ -40,7 +48,6 @@ describe('', () => {
describe('', () => {
it('should render the DeleteLanguageModal form, and do add language', () => {
- jest.useFakeTimers();
const onSubmit = jest.fn(() => {});
const onDismiss = jest.fn(() => {});
const { getByText } = render(
diff --git a/Composer/packages/client/__tests__/components/skill.test.tsx b/Composer/packages/client/__tests__/components/skill.test.tsx
index 6855a4d258..2eb89ade80 100644
--- a/Composer/packages/client/__tests__/components/skill.test.tsx
+++ b/Composer/packages/client/__tests__/components/skill.test.tsx
@@ -44,33 +44,38 @@ describe('Skill page', () => {
describe('', () => {
it('should render the skill form, and update skill manifest url', () => {
- jest.useFakeTimers();
+ try {
+ jest.useFakeTimers();
- (httpClient.get as jest.Mock).mockResolvedValue({ endpoints: [] });
+ (httpClient.get as jest.Mock).mockResolvedValue({ endpoints: [] });
- const onDismiss = jest.fn();
- const onSubmit = jest.fn();
- const { getByLabelText, getByText } = renderWithRecoil(
- ,
- recoilInitState
- );
+ const onDismiss = jest.fn();
+ const onSubmit = jest.fn();
+ const { getByLabelText, getByText } = renderWithRecoil(
+ ,
+ recoilInitState
+ );
- const urlInput = getByLabelText('Manifest url');
- act(() => {
- fireEvent.change(urlInput, {
- target: { value: 'https://onenote-dev.azurewebsites.net/manifests/OneNoteSync-2-1-preview-1-manifest.json' },
+ const urlInput = getByLabelText('Manifest url');
+ act(() => {
+ fireEvent.change(urlInput, {
+ target: { value: 'https://onenote-dev.azurewebsites.net/manifests/OneNoteSync-2-1-preview-1-manifest.json' },
+ });
});
- });
- expect(urlInput.getAttribute('value')).toBe(
- 'https://onenote-dev.azurewebsites.net/manifests/OneNoteSync-2-1-preview-1-manifest.json'
- );
+ expect(urlInput.getAttribute('value')).toBe(
+ 'https://onenote-dev.azurewebsites.net/manifests/OneNoteSync-2-1-preview-1-manifest.json'
+ );
- const submitButton = getByText('Confirm');
- act(() => {
- fireEvent.click(submitButton);
- });
- expect(onSubmit).not.toBeCalled();
+ const submitButton = getByText('Confirm');
+ act(() => {
+ fireEvent.click(submitButton);
+ });
+ expect(onSubmit).not.toBeCalled();
+ } finally {
+ jest.runOnlyPendingTimers();
+ jest.useRealTimers();
+ }
});
let formDataErrors;
diff --git a/Composer/packages/client/src/components/Notifications/__tests__/NotificationCard.test.tsx b/Composer/packages/client/src/components/Notifications/__tests__/NotificationCard.test.tsx
index 4cb7b63c34..ed1e9bf305 100644
--- a/Composer/packages/client/src/components/Notifications/__tests__/NotificationCard.test.tsx
+++ b/Composer/packages/client/src/components/Notifications/__tests__/NotificationCard.test.tsx
@@ -7,7 +7,13 @@ import { renderWithRecoil } from '../../../../__tests__/testUtils/renderWithReco
import { NotificationCard, CardProps } from '../NotificationCard';
import Timer from '../../../utils/timer';
-jest.useFakeTimers();
+beforeAll(() => {
+ jest.useFakeTimers();
+});
+afterAll(() => {
+ jest.runOnlyPendingTimers();
+ jest.useRealTimers();
+});
describe('', () => {
it('should render the NotificationCard', () => {
diff --git a/Composer/packages/client/src/components/__tests__/BotRuntimeController/BotRuntimeStatus.test.tsx b/Composer/packages/client/src/components/__tests__/BotRuntimeController/BotRuntimeStatus.test.tsx
index e7d65459b2..9f1e68fb36 100644
--- a/Composer/packages/client/src/components/__tests__/BotRuntimeController/BotRuntimeStatus.test.tsx
+++ b/Composer/packages/client/src/components/__tests__/BotRuntimeController/BotRuntimeStatus.test.tsx
@@ -41,6 +41,14 @@ describe('', () => {
});
describe('', () => {
+ beforeAll(() => {
+ jest.useFakeTimers();
+ });
+ afterAll(() => {
+ jest.runOnlyPendingTimers();
+ jest.useRealTimers();
+ });
+
const updatePublishStatusMock = jest.fn();
(httpClient.get as jest.Mock).mockImplementation(() => {
updatePublishStatusMock();
@@ -53,15 +61,11 @@ describe('', () => {
});
});
});
+
beforeEach(() => {
- jest.useFakeTimers();
updatePublishStatusMock.mockClear();
});
- afterEach(() => {
- jest.useRealTimers();
- });
-
it('should not poll if bot is started', async () => {
renderWithRecoil(, ({ set }) => {
set(botStatusState(projectId), BotStatus.connected);
diff --git a/Composer/packages/client/src/recoilModel/dispatchers/__tests__/user.test.ts b/Composer/packages/client/src/recoilModel/dispatchers/__tests__/user.test.ts
index 3fe1839149..47bd596d5e 100644
--- a/Composer/packages/client/src/recoilModel/dispatchers/__tests__/user.test.ts
+++ b/Composer/packages/client/src/recoilModel/dispatchers/__tests__/user.test.ts
@@ -23,14 +23,16 @@ jest.mock('../../../utils/auth', () => {
};
});
jest.mock('jwt-decode');
-jest.useFakeTimers();
beforeAll(() => {
+ jest.useFakeTimers();
global.Date.now = jest.fn(() => 10000000);
});
afterAll(() => {
global.Date.now = realDate;
+ jest.runOnlyPendingTimers();
+ jest.useRealTimers();
});
const mockGetUserToken = getUserTokenFromCache as jest.Mock;
diff --git a/Composer/packages/electron-server/__tests__/utility/machineId.test.ts b/Composer/packages/electron-server/__tests__/utility/machineId.test.ts
index dc3c647c05..87cf8f0cdd 100644
--- a/Composer/packages/electron-server/__tests__/utility/machineId.test.ts
+++ b/Composer/packages/electron-server/__tests__/utility/machineId.test.ts
@@ -1,7 +1,10 @@
-import { getMac, getMacAddress } from '../../src/utility/getMacAddress';
+// Copyright (c) Microsoft Corporation.
+// Licensed under the MIT License.
import { networkInterfaces } from 'os';
+import { getMac, getMacAddress } from '../../src/utility/getMacAddress';
+
jest.mock('os');
describe('getMac', () => {
@@ -35,10 +38,16 @@ describe('getMacAddress', () => {
});
it('throws timeout error', async () => {
- (networkInterfaces as jest.Mock).mockReturnValue({});
- jest.useFakeTimers();
- const macAddress = getMacAddress();
- jest.advanceTimersToNextTimer(10001);
- expect(macAddress).rejects.toEqual('Timeout: Unable to retrieve mac address');
+ try {
+ jest.useFakeTimers();
+ (networkInterfaces as jest.Mock).mockReturnValue({});
+
+ const macAddress = getMacAddress();
+ jest.advanceTimersToNextTimer(10001);
+ expect(macAddress).rejects.toEqual('Timeout: Unable to retrieve mac address');
+ } finally {
+ jest.runOnlyPendingTimers();
+ jest.useRealTimers();
+ }
});
});
diff --git a/Composer/packages/lib/code-editor/src/components/toolbar/__tests__/ToolbarButtonMenu.test.tsx b/Composer/packages/lib/code-editor/src/components/toolbar/__tests__/ToolbarButtonMenu.test.tsx
index 254cc34e57..725874cd0b 100644
--- a/Composer/packages/lib/code-editor/src/components/toolbar/__tests__/ToolbarButtonMenu.test.tsx
+++ b/Composer/packages/lib/code-editor/src/components/toolbar/__tests__/ToolbarButtonMenu.test.tsx
@@ -14,7 +14,13 @@ import { FunctionRefPayload, PropertyRefPayload, TemplateRefPayload } from '../.
getRandomValues: (arr: any[]) => crypto.randomBytes(arr.length),
};
-jest.useFakeTimers();
+beforeAll(() => {
+ jest.useFakeTimers();
+});
+afterAll(() => {
+ jest.runOnlyPendingTimers();
+ jest.useRealTimers();
+});
const templatePayload: TemplateRefPayload = {
kind: 'template',
diff --git a/Composer/packages/lib/code-editor/src/hooks/__tests__/useDebounce.test.tsx b/Composer/packages/lib/code-editor/src/hooks/__tests__/useDebounce.test.tsx
index 5fed4f1b70..2097056f59 100644
--- a/Composer/packages/lib/code-editor/src/hooks/__tests__/useDebounce.test.tsx
+++ b/Composer/packages/lib/code-editor/src/hooks/__tests__/useDebounce.test.tsx
@@ -6,7 +6,13 @@ import React from 'react';
import { useDebounce } from '../useDebounce';
-jest.useFakeTimers();
+beforeAll(() => {
+ jest.useFakeTimers();
+});
+afterAll(() => {
+ jest.runOnlyPendingTimers();
+ jest.useRealTimers();
+});
describe('useDebounce', () => {
it('put initialized value in first render', () => {
diff --git a/Composer/packages/lib/code-editor/src/lu/__test__/DefineEntityButton.test.tsx b/Composer/packages/lib/code-editor/src/lu/__test__/DefineEntityButton.test.tsx
index cfa42f2114..383c6b715e 100644
--- a/Composer/packages/lib/code-editor/src/lu/__test__/DefineEntityButton.test.tsx
+++ b/Composer/packages/lib/code-editor/src/lu/__test__/DefineEntityButton.test.tsx
@@ -6,7 +6,13 @@ import React from 'react';
import { DefineEntityButton } from '../DefineEntityButton';
-jest.useFakeTimers();
+beforeAll(() => {
+ jest.useFakeTimers();
+});
+afterAll(() => {
+ jest.runOnlyPendingTimers();
+ jest.useRealTimers();
+});
describe('', () => {
it('Should call onDefineEntity callback when a menu item is clicked', () => {
diff --git a/Composer/packages/lib/code-editor/src/lu/__test__/InsertEntityButton.test.tsx b/Composer/packages/lib/code-editor/src/lu/__test__/InsertEntityButton.test.tsx
index 5454666b05..998b2858c6 100644
--- a/Composer/packages/lib/code-editor/src/lu/__test__/InsertEntityButton.test.tsx
+++ b/Composer/packages/lib/code-editor/src/lu/__test__/InsertEntityButton.test.tsx
@@ -43,7 +43,13 @@ const luFile: LuFile = {
isContentUnparsed: false,
};
-jest.useFakeTimers();
+beforeAll(() => {
+ jest.useFakeTimers();
+});
+afterAll(() => {
+ jest.runOnlyPendingTimers();
+ jest.useRealTimers();
+});
describe('', () => {
it('Should call onInsertEntity callback when a menu item is clicked', () => {
diff --git a/Composer/packages/ui-plugins/select-dialog/src/__tests__/selectDialog.test.tsx b/Composer/packages/ui-plugins/select-dialog/src/__tests__/selectDialog.test.tsx
index c40d66b874..9f2062df4b 100644
--- a/Composer/packages/ui-plugins/select-dialog/src/__tests__/selectDialog.test.tsx
+++ b/Composer/packages/ui-plugins/select-dialog/src/__tests__/selectDialog.test.tsx
@@ -40,9 +40,13 @@ const renderSelectDialog = ({ createDialog, navTo, onChange } = {}) => {
};
describe('Select Dialog', () => {
- beforeEach(() => {
+ beforeAll(() => {
jest.useFakeTimers();
});
+ afterAll(() => {
+ jest.runOnlyPendingTimers();
+ jest.useRealTimers();
+ });
it('should create a new dialog', async () => {
const createDialog = jest.fn().mockResolvedValue('newDialog');