1- // RNTL types `ReactTestInstance.props` as `any`, so reading a queried input's `.props.value` is an
2- // unavoidably unsafe access, and the jest factories that spread `requireActual` results are untyped at
3- // that boundary. The type assertion builds a route whose `action`/`backTo` params are typed `never`
4- // but are read at runtime by the screen under test.
5- // These are the only reason for the file-wide disables; nothing here silences a production-code rule.
6- /* eslint-disable @typescript-eslint/no-unsafe-assignment */
7- /* eslint-disable @typescript-eslint/no-unsafe-member-access */
8- /* eslint-disable @typescript-eslint/no-unsafe-call */
9- /* eslint-disable @typescript-eslint/no-unsafe-return */
10- /* eslint-disable @typescript-eslint/no-unsafe-type-assertion */
111import { act , fireEvent , render , screen } from '@testing-library/react-native' ;
122
133import { CurrentUserPersonalDetailsProvider } from '@components/CurrentUserPersonalDetailsProvider' ;
144import OnyxListItemProvider from '@components/OnyxListItemProvider' ;
155
6+ import type { MoneyRequestNavigatorParamList } from '@libs/Navigation/types' ;
7+
168import DynamicIOURequestStepDistanceManual from '@pages/iou/request/step/DynamicIOURequestStepDistanceManual' ;
179
1810import CONST from '@src/CONST' ;
@@ -32,6 +24,13 @@ import waitForBatchedUpdatesWithAct from '../utils/waitForBatchedUpdatesWithAct'
3224// what the guard reads. Capturing react-navigation's `usePreventRemove` flag instead does not work here:
3325// `ScreenWrapper/index.tsx:216` calls that hook too and renders last, so its `false` wins.
3426let mockGetHasUnsavedChanges : ( ( ) => boolean ) | undefined ;
27+ // Only the two React APIs this factory needs. A namespace import of 'react' trips no-restricted-imports,
28+ // and `typeof import(...)` is banned, so name them off the default import instead (types are erased).
29+ type ReactFactoryApi = {
30+ createContext : typeof React . createContext ;
31+ createElement : typeof React . createElement ;
32+ } ;
33+
3534jest . mock ( '@hooks/useDiscardChangesConfirmation' , ( ) => ( {
3635 __esModule : true ,
3736 default : ( options : { getHasUnsavedChanges : ( ) => boolean } ) => {
@@ -41,7 +40,7 @@ jest.mock('@hooks/useDiscardChangesConfirmation', () => ({
4140} ) ) ;
4241
4342jest . mock ( '@components/LocaleContextProvider' , ( ) => {
44- const React2 = require ( 'react' ) ;
43+ const React2 = jest . requireActual < ReactFactoryApi > ( 'react' ) ;
4544
4645 const defaultContextValue = {
4746 translate : ( path : string ) => path ,
@@ -144,6 +143,17 @@ function createDistanceTransaction(): Transaction {
144143 } ;
145144}
146145
146+ // The route types `action`/`backTo` as `never` (unused for navigation but read at runtime by the screen
147+ // under test), so the params object cannot be built without one assertion.
148+ // eslint-disable-next-line @typescript-eslint/no-unsafe-type-assertion -- see comment above
149+ const EDIT_ROUTE_PARAMS = {
150+ action : CONST . IOU . ACTION . EDIT ,
151+ iouType : CONST . IOU . TYPE . SUBMIT ,
152+ reportID : REPORT_ID ,
153+ transactionID : TRANSACTION_ID ,
154+ backTo : undefined ,
155+ } as unknown as MoneyRequestNavigatorParamList [ typeof SCREENS . MONEY_REQUEST . DYNAMIC_STEP_DISTANCE_MANUAL ] ;
156+
147157function renderEditMode ( ) {
148158 return render (
149159 < OnyxListItemProvider >
@@ -152,13 +162,7 @@ function renderEditMode() {
152162 route = { {
153163 key : 'Dynamic_Money_Request_Step_Distance_Manual-test' ,
154164 name : SCREENS . MONEY_REQUEST . DYNAMIC_STEP_DISTANCE_MANUAL ,
155- params : {
156- action : CONST . IOU . ACTION . EDIT as never ,
157- iouType : CONST . IOU . TYPE . SUBMIT ,
158- reportID : REPORT_ID ,
159- transactionID : TRANSACTION_ID ,
160- backTo : undefined as never ,
161- } ,
165+ params : EDIT_ROUTE_PARAMS ,
162166 } }
163167 // @ts -expect-error minimal navigation for test
164168 navigation = { undefined }
0 commit comments