Skip to content

Commit

Permalink
Merge pull request #42256 from ZhenjaHorbach/remove-unnecessary-ts-ex…
Browse files Browse the repository at this point in the history
…pect-error-testHelper

TS issues related with TestHelper
  • Loading branch information
Beamanator authored May 16, 2024
2 parents f16005f + 3a9a1a5 commit 5900fea
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 43 deletions.
34 changes: 13 additions & 21 deletions tests/actions/PolicyCategoryTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import ONYXKEYS from '@src/ONYXKEYS';
import createRandomPolicy from '../utils/collections/policies';
import createRandomPolicyCategories from '../utils/collections/policyCategory';
import * as TestHelper from '../utils/TestHelper';
import type {MockFetch} from '../utils/TestHelper';
import waitForBatchedUpdates from '../utils/waitForBatchedUpdates';

OnyxUpdateManager();
Expand All @@ -16,9 +17,10 @@ describe('actions/PolicyCategory', () => {
});
});

let mockFetch: MockFetch;
beforeEach(() => {
// @ts-expect-error TODO: Remove this once TestHelper (https://github.com/Expensify/App/issues/25318) is migrated to TypeScript.
global.fetch = TestHelper.getGlobalFetchMock();
mockFetch = fetch as MockFetch;
return Onyx.clear().then(waitForBatchedUpdates);
});

Expand All @@ -27,8 +29,7 @@ describe('actions/PolicyCategory', () => {
const fakePolicy = createRandomPolicy(0);
fakePolicy.requiresCategory = false;

// @ts-expect-error TODO: Remove this once TestHelper (https://github.com/Expensify/App/issues/25318) is migrated to TypeScript.
fetch.pause();
mockFetch?.pause?.();
Onyx.set(`${ONYXKEYS.COLLECTION.POLICY}${fakePolicy.id}`, fakePolicy);
Policy.setWorkspaceRequiresCategory(fakePolicy.id, true);
await waitForBatchedUpdates();
Expand All @@ -46,8 +47,7 @@ describe('actions/PolicyCategory', () => {
},
});
});
// @ts-expect-error TODO: Remove this once TestHelper (https://github.com/Expensify/App/issues/25318) is migrated to TypeScript.
await fetch.resume();
await mockFetch?.resume?.();
await waitForBatchedUpdates();
await new Promise<void>((resolve) => {
const connectionID = Onyx.connect({
Expand All @@ -68,8 +68,7 @@ describe('actions/PolicyCategory', () => {
const fakePolicy = createRandomPolicy(0);
const fakeCategories = createRandomPolicyCategories(3);
const newCategoryName = 'New category';
// @ts-expect-error TODO: Remove this once TestHelper (https://github.com/Expensify/App/issues/25318) is migrated to TypeScript.
fetch.pause();
mockFetch?.pause?.();
Onyx.set(`${ONYXKEYS.COLLECTION.POLICY}${fakePolicy.id}`, fakePolicy);
Onyx.set(`${ONYXKEYS.COLLECTION.POLICY_CATEGORIES}${fakePolicy.id}`, fakeCategories);
Policy.createPolicyCategory(fakePolicy.id, newCategoryName);
Expand All @@ -89,8 +88,7 @@ describe('actions/PolicyCategory', () => {
},
});
});
// @ts-expect-error TODO: Remove this once TestHelper (https://github.com/Expensify/App/issues/25318) is migrated to TypeScript.
await fetch.resume();
await mockFetch?.resume?.();
await waitForBatchedUpdates();
await new Promise<void>((resolve) => {
const connectionID = Onyx.connect({
Expand All @@ -115,8 +113,7 @@ describe('actions/PolicyCategory', () => {
const fakeCategories = createRandomPolicyCategories(3);
const oldCategoryName = Object.keys(fakeCategories)[0];
const newCategoryName = 'Updated category';
// @ts-expect-error TODO: Remove this once TestHelper (https://github.com/Expensify/App/issues/25318) is migrated to TypeScript.
fetch.pause();
mockFetch?.pause?.();
Onyx.set(`${ONYXKEYS.COLLECTION.POLICY}${fakePolicy.id}`, fakePolicy);
Onyx.set(`${ONYXKEYS.COLLECTION.POLICY_CATEGORIES}${fakePolicy.id}`, fakeCategories);
Policy.renamePolicyCategory(fakePolicy.id, {
Expand All @@ -140,8 +137,7 @@ describe('actions/PolicyCategory', () => {
},
});
});
// @ts-expect-error TODO: Remove this once TestHelper (https://github.com/Expensify/App/issues/25318) is migrated to TypeScript.
await fetch.resume();
await mockFetch?.resume?.();
await waitForBatchedUpdates();
await new Promise<void>((resolve) => {
const connectionID = Onyx.connect({
Expand Down Expand Up @@ -170,8 +166,7 @@ describe('actions/PolicyCategory', () => {
enabled: true,
},
};
// @ts-expect-error TODO: Remove this once TestHelper (https://github.com/Expensify/App/issues/25318) is migrated to TypeScript.
fetch.pause();
mockFetch?.pause?.();
Onyx.set(`${ONYXKEYS.COLLECTION.POLICY}${fakePolicy.id}`, fakePolicy);
Onyx.set(`${ONYXKEYS.COLLECTION.POLICY_CATEGORIES}${fakePolicy.id}`, fakeCategories);
Policy.setWorkspaceCategoryEnabled(fakePolicy.id, categoriesToUpdate);
Expand All @@ -191,8 +186,7 @@ describe('actions/PolicyCategory', () => {
},
});
});
// @ts-expect-error TODO: Remove this once TestHelper (https://github.com/Expensify/App/issues/25318) is migrated to TypeScript.
await fetch.resume();
await mockFetch?.resume?.();
await waitForBatchedUpdates();
await new Promise<void>((resolve) => {
const connectionID = Onyx.connect({
Expand All @@ -217,8 +211,7 @@ describe('actions/PolicyCategory', () => {
const fakeCategories = createRandomPolicyCategories(3);
const categoryNameToDelete = Object.keys(fakeCategories)[0];
const categoriesToDelete = [categoryNameToDelete];
// @ts-expect-error TODO: Remove this once TestHelper (https://github.com/Expensify/App/issues/25318) is migrated to TypeScript.
fetch.pause();
mockFetch?.pause?.();
Onyx.set(`${ONYXKEYS.COLLECTION.POLICY}${fakePolicy.id}`, fakePolicy);
Onyx.set(`${ONYXKEYS.COLLECTION.POLICY_CATEGORIES}${fakePolicy.id}`, fakeCategories);
Policy.deleteWorkspaceCategories(fakePolicy.id, categoriesToDelete);
Expand All @@ -235,8 +228,7 @@ describe('actions/PolicyCategory', () => {
},
});
});
// @ts-expect-error TODO: Remove this once TestHelper (https://github.com/Expensify/App/issues/25318) is migrated to TypeScript.
await fetch.resume();
await mockFetch?.resume?.();
await waitForBatchedUpdates();
await new Promise<void>((resolve) => {
const connectionID = Onyx.connect({
Expand Down
28 changes: 11 additions & 17 deletions tests/actions/PolicyMemberTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import createRandomPolicy from '../utils/collections/policies';
import createRandomReportAction from '../utils/collections/reportActions';
import createRandomReport from '../utils/collections/reports';
import * as TestHelper from '../utils/TestHelper';
import type {MockFetch} from '../utils/TestHelper';
import waitForBatchedUpdates from '../utils/waitForBatchedUpdates';

OnyxUpdateManager();
Expand All @@ -21,9 +22,10 @@ describe('actions/PolicyMember', () => {
});
});

let mockFetch: MockFetch;
beforeEach(() => {
// @ts-expect-error TODO: Remove this once TestHelper (https://github.com/Expensify/App/issues/25318) is migrated to TypeScript.
global.fetch = TestHelper.getGlobalFetchMock();
mockFetch = fetch as MockFetch;
return Onyx.clear().then(waitForBatchedUpdates);
});

Expand All @@ -39,8 +41,7 @@ describe('actions/PolicyMember', () => {
actionName: CONST.REPORT.ACTIONS.TYPE.ACTIONABLE_JOIN_REQUEST,
} as ReportAction;

// @ts-expect-error TODO: Remove this once TestHelper (https://github.com/Expensify/App/issues/25318) is migrated to TypeScript.
fetch.pause();
mockFetch?.pause?.();
Onyx.set(`${ONYXKEYS.COLLECTION.POLICY}${fakePolicy.id}`, fakePolicy);
Onyx.set(`${ONYXKEYS.COLLECTION.REPORT}${fakeReport.reportID}`, fakeReport);
Onyx.merge(`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${fakeReport.reportID}`, {
Expand All @@ -67,8 +68,7 @@ describe('actions/PolicyMember', () => {
},
});
});
// @ts-expect-error TODO: Remove this once TestHelper (https://github.com/Expensify/App/issues/25318) is migrated to TypeScript.
await fetch.resume();
await mockFetch?.resume?.();
await waitForBatchedUpdates();
await new Promise<void>((resolve) => {
const connectionID = Onyx.connect({
Expand Down Expand Up @@ -101,8 +101,7 @@ describe('actions/PolicyMember', () => {
},
};

// @ts-expect-error TODO: Remove this once TestHelper (https://github.com/Expensify/App/issues/25318) is migrated to TypeScript.
fetch.pause();
mockFetch?.pause?.();
Onyx.set(`${ONYXKEYS.COLLECTION.POLICY}${fakePolicy.id}`, fakePolicy);
Onyx.set(`${ONYXKEYS.PERSONAL_DETAILS_LIST}`, {[fakeUser2.accountID]: fakeUser2});
await waitForBatchedUpdates();
Expand All @@ -121,8 +120,7 @@ describe('actions/PolicyMember', () => {
},
});
});
// @ts-expect-error TODO: Remove this once TestHelper (https://github.com/Expensify/App/issues/25318) is migrated to TypeScript.
await fetch.resume();
await mockFetch?.resume?.();
await waitForBatchedUpdates();
await new Promise<void>((resolve) => {
const connectionID = Onyx.connect({
Expand All @@ -144,8 +142,7 @@ describe('actions/PolicyMember', () => {
const fakeEmail = '[email protected]';
const fakeAccountID = 1;

// @ts-expect-error TODO: Remove this once TestHelper (https://github.com/Expensify/App/issues/25318) is migrated to TypeScript.
fetch.pause();
mockFetch?.pause?.();
Onyx.set(`${ONYXKEYS.COLLECTION.POLICY}${fakePolicy.id}`, fakePolicy);
Onyx.merge(ONYXKEYS.SESSION, {email: fakeEmail, accountID: fakeAccountID});
Policy.requestWorkspaceOwnerChange(fakePolicy.id);
Expand All @@ -164,8 +161,7 @@ describe('actions/PolicyMember', () => {
},
});
});
// @ts-expect-error TODO: Remove this once TestHelper (https://github.com/Expensify/App/issues/25318) is migrated to TypeScript.
await fetch.resume();
await mockFetch?.resume?.();
await waitForBatchedUpdates();
await new Promise<void>((resolve) => {
const connectionID = Onyx.connect({
Expand Down Expand Up @@ -197,8 +193,7 @@ describe('actions/PolicyMember', () => {
};
const fakeAccountID = 1;

// @ts-expect-error TODO: Remove this once TestHelper (https://github.com/Expensify/App/issues/25318) is migrated to TypeScript.
fetch.pause();
mockFetch?.pause?.();
Onyx.set(`${ONYXKEYS.COLLECTION.POLICY}${fakePolicy.id}`, fakePolicy);
Onyx.merge(ONYXKEYS.SESSION, {email: fakeEmail, accountID: fakeAccountID});
Policy.addBillingCardAndRequestPolicyOwnerChange(fakePolicy.id, fakeCard);
Expand All @@ -217,8 +212,7 @@ describe('actions/PolicyMember', () => {
},
});
});
// @ts-expect-error TODO: Remove this once TestHelper (https://github.com/Expensify/App/issues/25318) is migrated to TypeScript.
await fetch.resume();
await mockFetch?.resume?.();
await waitForBatchedUpdates();
await new Promise<void>((resolve) => {
const connectionID = Onyx.connect({
Expand Down
10 changes: 5 additions & 5 deletions tests/actions/PolicyProfileTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import * as ReportUtils from '@src/libs/ReportUtils';
import ONYXKEYS from '@src/ONYXKEYS';
import createRandomPolicy from '../utils/collections/policies';
import * as TestHelper from '../utils/TestHelper';
import type {MockFetch} from '../utils/TestHelper';
import waitForBatchedUpdates from '../utils/waitForBatchedUpdates';

OnyxUpdateManager();
Expand All @@ -16,9 +17,10 @@ describe('actions/PolicyProfile', () => {
});
});

let mockFetch: MockFetch;
beforeEach(() => {
// @ts-expect-error TODO: Remove this once TestHelper (https://github.com/Expensify/App/issues/25318) is migrated to TypeScript.
global.fetch = TestHelper.getGlobalFetchMock();
mockFetch = fetch as MockFetch;
return Onyx.clear().then(waitForBatchedUpdates);
});

Expand All @@ -29,8 +31,7 @@ describe('actions/PolicyProfile', () => {
const oldDescription = fakePolicy.description ?? '';
const newDescription = 'Updated description';
const parsedDescription = ReportUtils.getParsedComment(newDescription);
// @ts-expect-error TODO: Remove this once TestHelper (https://github.com/Expensify/App/issues/25318) is migrated to TypeScript.
fetch.pause();
mockFetch?.pause?.();
Onyx.set(`${ONYXKEYS.COLLECTION.POLICY}${fakePolicy.id}`, fakePolicy);
Policy.updateWorkspaceDescription(fakePolicy.id, newDescription, oldDescription);
await waitForBatchedUpdates();
Expand All @@ -48,8 +49,7 @@ describe('actions/PolicyProfile', () => {
},
});
});
// @ts-expect-error TODO: Remove this once TestHelper (https://github.com/Expensify/App/issues/25318) is migrated to TypeScript.
await fetch.resume();
await mockFetch?.resume?.();
await waitForBatchedUpdates();
await new Promise<void>((resolve) => {
const connectionID = Onyx.connect({
Expand Down

0 comments on commit 5900fea

Please sign in to comment.