MCPcopy
hub / github.com/MetaMask/metamask-mobile / renderHookWithProvider

Function renderHookWithProvider

app/util/test/renderWithProvider.tsx:130–167  ·  view source on GitHub ↗
(
  hook: (props: Props) => Result,
  providerValues?: ProviderValues,
)

Source from the content-addressed store, hash-verified

128}
129
130export function renderHookWithProvider<Result, Props>(
131 hook: (props: Props) => Result,
132 providerValues?: ProviderValues,
133) {
134 const {
135 state = {},
136 uiMessenger = createMockUIMessenger(),
137 routeMessenger = null,
138 } = providerValues ?? {};
139
140 const store = configureStore(state);
141 // eslint-disable-next-line @typescript-eslint/no-require-imports, @typescript-eslint/no-var-requires
142 require('../../store')._updateMockState(state);
143
144 const Providers = ({ children }: { children: React.ReactElement }) => {
145 let wrappedChildren = children;
146 if (routeMessenger) {
147 wrappedChildren = (
148 <RouteMessengerContext.Provider value={routeMessenger}>
149 {wrappedChildren}
150 </RouteMessengerContext.Provider>
151 );
152 }
153
154 return (
155 <Provider store={store}>
156 <UIMessengerProvider value={uiMessenger}>
157 {wrappedChildren}
158 </UIMessengerProvider>
159 </Provider>
160 );
161 };
162
163 return {
164 ...renderHook(hook, { wrapper: Providers } as RenderHookOptions<Props>),
165 store,
166 };
167}

Calls 3

createMockUIMessengerFunction · 0.90
configureStoreFunction · 0.85
renderHookFunction · 0.50

Tested by 15

runHookFunction · 0.72
runHookFunction · 0.72
runHookFunction · 0.72
renderHookFunction · 0.72
runHookFunction · 0.72
runHookFunction · 0.72
runHookFunction · 0.72
runHookFunction · 0.72
runHookFunction · 0.72
runHookFunction · 0.72
runHookFunction · 0.72
runHookFunction · 0.72