[No QA] Remove unsafe type assertions from unit tests - #97530
Conversation
|
@ikevin127 Please copy/paste the Reviewer Checklist from here into a new comment on this PR and complete it. If you have the K2 extension, you can simply click: [this button] |
Reviewer Checklist
|
| const stubTranslate: LocaleContextProps['translate'] = <TPath extends TranslationPaths>(path: TPath, ...parameters: TranslationParameters<TPath>) => { | ||
| if (parameters.length > 0) { | ||
| return path; | ||
| } | ||
| return path; | ||
| }; |
There was a problem hiding this comment.
🟡 tests/unit/HrUtilsTest.ts:122 stubTranslate: Dead conditional, both branches return path
This is the same no-op parameters-gate that showed up in #97479 (FileUtils/useAutoCreateSubmitWorkspace). It reads like an unfinished interpolation and a future reader can't tell if it's intentional.
Rest params don't trip unused-var lint, so just const stubTranslate: LocaleContextProps['translate'] = (path) => path;.
Worth stamping out consistently across the series before it keeps propagating ❌
| mockListIssues.mockImplementation((...parameters: ListForRepoParameters): Promise<ListForRepoResponse> => { | ||
| const receivedParameters = parameters[0]; | ||
| if (!receivedParameters) { | ||
| throw new Error('GithubUtils issues.listForRepo mock requires request parameters.'); | ||
| } | ||
| let labels: string | undefined; | ||
| if ('url' in receivedParameters) { | ||
| const {url} = receivedParameters; | ||
| if (typeof url !== 'string') { | ||
| throw new Error('GithubUtils issues.listForRepo request options require a string URL.'); | ||
| } | ||
| labels = new URL(url).searchParams.get('labels') ?? undefined; | ||
| } else { | ||
| labels = receivedParameters.labels; | ||
| } | ||
| if (labels === CONST.LABELS.STAGING_DEPLOY) { | ||
| return Promise.resolve(createMock<ListForRepoResponse>({data: [closedDeployChecklist], headers: {}})); |
There was a problem hiding this comment.
🟡 DRY: tests/unit/createOrUpdateDeployChecklistTest.ts: The mockListIssues.mockImplementation((...parameters) => { ...guard... ; url-or-direct label extraction ; ... }) block is copy-pasted ~10 times (~18 lines each, ~180 lines total).
Every copy is byte-identical except the returned data. Extract one helper and pass just the label → response map:
function mockListIssuesByLabel(responseByLabel: Partial<Record<string, OctokitIssueItem[]>>) {
mockListIssues.mockImplementation((...parameters: ListForRepoParameters): Promise<ListForRepoResponse> => {
const received = parameters[0];
if (!received) throw new Error('GithubUtils issues.listForRepo mock requires request parameters.');
let labels: string | undefined;
if ('url' in received) {
if (typeof received.url !== 'string') throw new Error('listForRepo request options require a string URL.');
labels = new URL(received.url).searchParams.get('labels') ?? undefined;
} else {
labels = received.labels;
}
return Promise.resolve(createMock<ListForRepoResponse>({data: (labels && responseByLabel[labels]) ?? [], headers: {}}));
});
}Why it matters: this is the file most likely to be touched again (octokit/paginate is fiddly), and 10 identical url-parsing blocks means 10 places to fix when the shape shifts. The dedup also makes each test read as "STAGING_DEPLOY returns these issues" instead of 18 lines of plumbing.
ikevin127
left a comment
There was a problem hiding this comment.
🟢 LGTM - Only two 🟡 non-blocking comments ☝️
Solid cleanup, same series as #97285 / #97317 / #97479, but this one carries more genuine logic change than its siblings (the deploy-checklist octokit rewrite, the PolicyChangeLog orphan-check restructure, dozens of Card/CardsList fixtures gaining now-required fields). All of it is production-derived typing done carefully, and the author flagged the two riskiest edits in the description ✅
Explanation of Change
Removed
@typescript-eslint/no-unsafe-type-assertionviolations from 15 unit-test files as part of Expensify/App issue #94739.What changed:
Why this approach is safe:
AddressSearchdiagnostic outside this PR.b1a113c87e6888a1fdc3cb2eaafb9c78aca1f45ein provider run30588995129.Fixed Issues
$ #94739
PROPOSAL: #94739 (comment)
Tests
git diff --checkand verify the tracked Seatbelt TSV remains byte-identical.30588995129passes typecheck, lint, format, React Compiler, and Jest for commitb1a113c87e6888a1fdc3cb2eaafb9c78aca1f45e.Failure-scenario coverage is supplied by the existing focused Jest scenarios. Browser/device console checks and manual platform execution are not applicable to this test-only change.
Offline tests
Not applicable because this is a test-only type-safety cleanup with no production network, storage, or offline behavior changes.
QA Steps
Not applicable for staging or production QA because production behavior and user-interface code are unchanged. Validation is fully automated by focused verification, independent review, and exact-head Fork CI.
PR Author Checklist
### Fixed Issuessection aboveTestssectionOffline stepssectionQA stepssectionAvatar, I verified the components usingAvatarare working as expected)StyleUtils.getBackgroundAndBorderStyle(theme.componentBG))npm run compress-svg)Avataris modified, I verified thatAvataris working as expected in all cases)Designlabel and/or tagged@Expensify/designso the design team can review the changes.mainbranch was merged into this PR after a review, I tested again and verified the outcome was still expected according to theTeststeps.Count change
Current baseline source:
config/eslint/eslint.seatbelt.tsvat pinned base1abb329427c79458aeca2e8e5f66d6fe6e5f1262.Before:
tests/unit/FailureNotifierTest.ts: 4 violationstests/unit/HrUtilsTest.ts: 4 violationstests/unit/OnyxUpdateManagerTest.ts: 4 violationstests/unit/PolicyChangeLogContentTest.tsx: 4 violationstests/unit/PopoverMenuV2Test.tsx: 4 violationstests/unit/ReceiptAlternativeMethodsTest.tsx: 4 violationstests/unit/RefreshCardFeedConnectionPageTest.tsx: 4 violationstests/unit/components/MultifactorAuthentication/processing.test.ts: 4 violationstests/unit/createOrUpdateDeployChecklistTest.ts: 4 violationstests/unit/generateTranslationsTest.ts: 4 violationstests/unit/hooks/useCompanyCards.test.ts: 4 violationstests/unit/hooks/useRestoreWorkspacesTabOnNavigate.test.ts: 4 violationstests/unit/hooks/useSplitParticipants.test.tsx: 4 violationstests/unit/isDeployChecklistLockedTest.ts: 4 violationstests/unit/libs/PersonalDetailsUtilsTest.ts: 4 violationsAfter:
Net reduction:
@typescript-eslint/no-unsafe-type-assertionviolations across 15 files.TSV evidence:
config/eslint/eslint.seatbelt.tsvbyte-for-byte afterward.main.Screenshots/Videos
Not applicable on Android Native, Android mWeb Chrome, iOS Native, iOS mWeb Safari, or MacOS Chrome/Safari because this PR changes only test implementation and has no visual output.
Changed files (15)
tests/unit/FailureNotifierTest.tstests/unit/HrUtilsTest.tstests/unit/OnyxUpdateManagerTest.tstests/unit/PolicyChangeLogContentTest.tsxtests/unit/PopoverMenuV2Test.tsxtests/unit/ReceiptAlternativeMethodsTest.tsxtests/unit/RefreshCardFeedConnectionPageTest.tsxtests/unit/components/MultifactorAuthentication/processing.test.tstests/unit/createOrUpdateDeployChecklistTest.tstests/unit/generateTranslationsTest.tstests/unit/hooks/useCompanyCards.test.tstests/unit/hooks/useRestoreWorkspacesTabOnNavigate.test.tstests/unit/hooks/useSplitParticipants.test.tsxtests/unit/isDeployChecklistLockedTest.tstests/unit/libs/PersonalDetailsUtilsTest.ts