[No QA] Remove unsafe type assertions from ten test files - #97285
[No QA] Remove unsafe type assertions from ten test files#97285KJ21-ENG wants to merge 1 commit into
Conversation
3ec4b84 to
7844373
Compare
|
@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
|
|
|
||
| it('correctly handles reportNextStep parameter when moving transactions to unreported report', async () => { | ||
| const mockAPIWrite = jest.spyOn(require('@libs/API'), 'write').mockImplementation(() => Promise.resolve()); | ||
| // eslint-disable-next-line rulesdir/no-multiple-api-calls -- Spy on API.write to inspect the generated failure data. |
There was a problem hiding this comment.
🟡 tests/unit/TransactionTest.ts: The rulesdir/no-multiple-api-calls suppression is applied inconsistently across the jest.spyOn(API, 'write') sites.
The first converted site (correctly handles reportNextStep parameter when moving transactions between reports) has no disable comment, while the later identical spies all got // eslint-disable-next-line rulesdir/no-multiple-api-calls. If lint is green, one of the two forms is unnecessary.
Please make them consistent so a future reader doesn't assume the first site is special.
| expect(typeof session.authToken).toBe('string'); | ||
| expect(typeof session.encryptedAuthToken).toBe('string'); | ||
| expect(typeof preservedUserSession.authToken).toBe('string'); | ||
| expect(typeof preservedUserSession.encryptedAuthToken).toBe('string'); | ||
| if ( | ||
| typeof session.authToken !== 'string' || | ||
| typeof session.encryptedAuthToken !== 'string' || | ||
| typeof preservedUserSession.authToken !== 'string' || | ||
| typeof preservedUserSession.encryptedAuthToken !== 'string' | ||
| ) { | ||
| throw new Error('Expected masked session tokens'); | ||
| } |
There was a problem hiding this comment.
🟢 tests/unit/ExportOnyxStateTest.ts: The expect(typeof x).toBe('string') immediately followed by if (typeof x !== 'string') { throw ... } pair is repeated ~10 times.
The if/throw is needed for TS narrowing (expect doesn't narrow), but the two together are verbose. A tiny typed assertion helper collapses each pair to one line and reads better:
function assertString(value: unknown): asserts value is string {
expect(typeof value).toBe('string');
if (typeof value !== 'string') {
throw new Error('Expected a string');
}
}
// usage
assertString(session.authToken);
expect(session.authToken).toHaveLength('sensitive-auth-token'.length);Not blocking, just noise reduction if you touch this file again.
| (useCardFeeds as jest.Mock).mockReturnValue([{}, {status: 'loaded'}]); | ||
| mockedUseCardFeeds.mockReturnValue([{}, loadedResultMetadata, undefined, emptyCardFeedStatuses, mockWorkspaceAccountID]); | ||
| const {result, rerender} = renderHook(() => useIsBlockedToAddFeed(mockPolicyID)); | ||
| expect(result.current.isBlockedToAddNewFeeds).toBe(false); |
There was a problem hiding this comment.
🟢 tests/unit/hooks/useIsBlockedToAddFeed.test.ts: Fixtures moved from literal keys ('plaid.ins_19', 'csv#123456') to computed getCardFeedWithDomainID(FEED_BANK_NAME.MOCK_BANK / CSV_CLASSIC, mockWorkspaceAccountID), and several feed fields were dropped (shouldApplyCashbackToBill, the Expensify settlement block, uploadLayoutSettings: [] → {}).
This is behavior-preserving and more realistic, but the assertions (isBlockedToAddNewFeeds toBe(true)) only stay meaningful if MOCK_BANK still classifies as a real, non-CSV / non-Expensify feed.
Worth a quick sanity confirm since the whole point of those cases is "a real feed exists."
|
@KJ21-ENG (3) comments above to be addressed before approval 🙌 |
Explanation of Change
This issue 94739 cleanup removes unsafe type assertions from ten test files. It replaces unsafe assertions with production-linked types and typed mocks, while preserving the intentional malformed persisted-data fixture through a localized TypeScript suppression. No production source files were changed.
Fixed Issues
$ #94739
PROPOSAL: #94739 (comment)
Count change
Current baseline source:
config/eslint/eslint.seatbelt.tsvBefore:
tests/actions/SessionTest.ts: 12 violationstests/ui/NetSuiteCustomListSelectorPageTest.tsx: 12 violationstests/unit/DebugUtilsTest.ts: 11 violationstests/unit/ExportOnyxStateTest.ts: 12 violationstests/unit/IOUUtilsTest.ts: 11 violationstests/unit/RequestConflictUtilsTest.ts: 11 violationstests/unit/TransactionTest.ts: 12 violationstests/unit/hooks/useGettingStartedItems.test.ts: 11 violationstests/unit/hooks/useIsBlockedToAddFeed.test.ts: 11 violationstests/unit/pages/home/GettingStartedSection/GettingStartedSectionTest.tsx: 11 violationsAfter:
Net reduction:
TSV evidence:
Tests
Deterministic cleanup verification reported zero findings for all ten authorized targets. Focused formatter and individually scoped lint checks passed for all ten targets. The executable focused Jest command covering all ten targets passed through the verifier-owned worktree resolver. Verifier-owned focused TypeScript was unavailable only because it reported an unrelated
src/components/AddressSearch/index.tsxdiagnostic; no authorized-path diagnostic was reported. Fresh exact-head Fork CI run30568612660passed typecheck, lint, format, React Compiler, and Jest for rebuilt head7844373e49573745ca3ea092cb996734ad0c1aae. No manual platform testing was performed.Offline tests
N/A — this is a test-only type-safety cleanup; no application runtime or network behavior changed.
QA Steps
N/A — this test-only cleanup requires no staging or manual QA testing; the title uses the
[No QA]prefix.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.Screenshots/Videos
N/A — test-only cleanup; no UI changes or platform screenshots were required.
Changed files (10)
tests/actions/SessionTest.tstests/ui/NetSuiteCustomListSelectorPageTest.tsxtests/unit/DebugUtilsTest.tstests/unit/ExportOnyxStateTest.tstests/unit/IOUUtilsTest.tstests/unit/RequestConflictUtilsTest.tstests/unit/TransactionTest.tstests/unit/hooks/useGettingStartedItems.test.tstests/unit/hooks/useIsBlockedToAddFeed.test.tstests/unit/pages/home/GettingStartedSection/GettingStartedSectionTest.tsx