@@ -26,6 +26,7 @@ import {
2626 KEYRING_SNAP_REMOVAL_WARNING_CONTINUE ,
2727 KEYRING_SNAP_REMOVAL_WARNING_TEXT_INPUT ,
2828} from '../../KeyringSnapRemovalWarning/KeyringSnapRemovalWarning.constants' ;
29+ import { createMockRouteMessenger } from '../../../../../util/test/mock-route-messenger' ;
2930
3031const MOCK_ACCOUNTS_CONTROLLER_STATE = createMockAccountsControllerState ( [
3132 MOCK_ADDRESS_1 ,
@@ -215,9 +216,6 @@ jest.mock('../../../../../core/Engine', () => {
215216 } ) ,
216217 removeAccount : jest . fn ( ) ,
217218 context : {
218- SnapController : {
219- removeSnap : jest . fn ( ) ,
220- } ,
221219 KeyringController : {
222220 state : {
223221 keyrings : [
@@ -248,11 +246,16 @@ describe('SnapSettings with non keyring snap', () => {
248246 } ) ;
249247
250248 it ( 'renders correctly' , ( ) => {
249+ const routeMessenger = createMockRouteMessenger ( {
250+ 'SnapController:removeSnap' : jest . fn ( ) ,
251+ } ) ;
252+
251253 const { getAllByTestId, getByTestId } = renderWithProvider (
252254 < SnapSettings /> ,
253255 {
254256 // eslint-disable-next-line @typescript-eslint/no-explicit-any
255257 state : initialState as any ,
258+ routeMessenger,
256259 } ,
257260 ) ;
258261
@@ -268,14 +271,22 @@ describe('SnapSettings with non keyring snap', () => {
268271 } ) ;
269272
270273 it ( 'remove snap and goes back when Remove button is pressed' , async ( ) => {
274+ const routeMessenger = createMockRouteMessenger ( {
275+ 'SnapController:removeSnap' : jest . fn ( ) ,
276+ } ) ;
277+
278+ jest . spyOn ( routeMessenger , 'call' ) ;
279+
271280 const { getByTestId } = renderWithProvider ( < SnapSettings /> , {
272281 // eslint-disable-next-line @typescript-eslint/no-explicit-any
273282 state : initialState as any ,
283+ routeMessenger,
274284 } ) ;
275285
276286 const removeButton = getByTestId ( SNAP_SETTINGS_REMOVE_BUTTON ) ;
277287 fireEvent ( removeButton , 'onPress' ) ;
278- expect ( Engine . context . SnapController . removeSnap ) . toHaveBeenCalledWith (
288+ expect ( routeMessenger . call ) . toHaveBeenCalledWith (
289+ 'SnapController:removeSnap' ,
279290 'npm:@chainsafe/filsnap' ,
280291 ) ;
281292 await waitFor ( ( ) => {
@@ -390,9 +401,14 @@ describe('SnapSettings with keyring snap', () => {
390401 } ;
391402
392403 it ( 'renders KeyringSnapRemovalWarning when removing a keyring snap' , async ( ) => {
404+ const routeMessenger = createMockRouteMessenger ( {
405+ 'SnapController:removeSnap' : jest . fn ( ) ,
406+ } ) ;
407+
393408 const { getByTestId } = renderWithProvider ( < SnapSettings /> , {
394409 // eslint-disable-next-line @typescript-eslint/no-explicit-any
395410 state : initialStateWithKeyringSnap as any ,
411+ routeMessenger,
396412 } ) ;
397413
398414 // Needed to allow for useEffect to run
@@ -406,10 +422,17 @@ describe('SnapSettings with keyring snap', () => {
406422 } ) ;
407423 } ) ;
408424
409- it ( 'calls Engine.context.SnapController and Engine.removeAccount when removing a keyring snap with accounts' , async ( ) => {
425+ it ( 'calls `SnapController:removeSnap` when removing a keyring snap with accounts' , async ( ) => {
426+ const routeMessenger = createMockRouteMessenger ( {
427+ 'SnapController:removeSnap' : jest . fn ( ) ,
428+ } ) ;
429+
430+ jest . spyOn ( routeMessenger , 'call' ) ;
431+
410432 const { getByTestId } = renderWithProvider ( < SnapSettings /> , {
411433 // eslint-disable-next-line @typescript-eslint/no-explicit-any
412434 state : initialStateWithKeyringSnap as any ,
435+ routeMessenger,
413436 } ) ;
414437
415438 // Needed to allow for useEffect to run
@@ -439,7 +462,8 @@ describe('SnapSettings with keyring snap', () => {
439462
440463 // Step 5: Verify that the removal functions are called
441464 await waitFor ( ( ) => {
442- expect ( Engine . context . SnapController . removeSnap ) . toHaveBeenCalledWith (
465+ expect ( routeMessenger . call ) . toHaveBeenCalledWith (
466+ 'SnapController:removeSnap' ,
443467 mockKeyringSnapId ,
444468 ) ;
445469 expect ( Engine . removeAccount ) . toHaveBeenCalledTimes ( 2 ) ;
0 commit comments