1- import React from 'react' ;
1+ import * as React from 'react' ;
22import { describe , it , expect , vi , beforeEach } from 'vitest' ;
33import { render , screen } from '@testing-library/react' ;
44import { Provider } from 'react-redux' ;
@@ -8,13 +8,32 @@ import { amount as sdkAmount } from '@wormhole-foundation/sdk';
88
99import FeeOffset from './FeeOffset' ;
1010import { dark } from 'theme' ;
11- import config from 'config' ;
12- import { createMockToken } from 'utils/testHelpers' ;
11+ import { createMockToken , TestConfigContext } from 'utils/testHelpers' ;
1312
1413const theme = createTheme ( {
1514 palette : dark as any ,
1615} ) ;
1716
17+ // Mock config object provided via TestConfigContext
18+ const mockConfig = {
19+ ui : {
20+ experimental : {
21+ feeOffsetting : true ,
22+ } ,
23+ } ,
24+ } ;
25+
26+ // Mock useConfig to read from TestConfigContext
27+ vi . mock ( 'contexts/ConfigContext' , ( ) => ( {
28+ useConfig : ( ) => {
29+ const context = React . useContext ( TestConfigContext ) ;
30+ if ( ! context ) {
31+ throw new Error ( 'useConfig must be used within a ConfigProvider' ) ;
32+ }
33+ return context ;
34+ } ,
35+ } ) ) ;
36+
1837// Mock the calculateFeeOffset function
1938vi . mock ( 'utils/fees' , ( ) => ( {
2039 calculateFeeOffset : vi . fn ( ) ,
@@ -28,17 +47,6 @@ vi.mock('hooks/useGetTokens', () => ({
2847 } ) ) ,
2948} ) ) ;
3049
31- // Mock the config module
32- vi . mock ( 'config' , ( ) => ( {
33- default : {
34- ui : {
35- experimental : {
36- feeOffsetting : true ,
37- } ,
38- } ,
39- } ,
40- } ) ) ;
41-
4250const mockToken = createMockToken ( {
4351 symbol : 'USDC' ,
4452 name : 'USD Coin' ,
@@ -61,9 +69,11 @@ const AppWrapper =
6169 ( store : any ) =>
6270 ( { children } : { children : React . ReactNode } ) =>
6371 (
64- < Provider store = { store } >
65- < ThemeProvider theme = { theme } > { children } </ ThemeProvider >
66- </ Provider >
72+ < TestConfigContext . Provider value = { mockConfig } >
73+ < Provider store = { store } >
74+ < ThemeProvider theme = { theme } > { children } </ ThemeProvider >
75+ </ Provider >
76+ </ TestConfigContext . Provider >
6777 ) ;
6878
6979describe ( 'FeeOffset' , ( ) => {
@@ -122,8 +132,13 @@ describe('FeeOffset', () => {
122132 const { calculateFeeOffset } = vi . mocked ( await import ( 'utils/fees' ) ) ;
123133 const { useGetTokens } = vi . mocked ( await import ( 'hooks/useGetTokens' ) ) ;
124134
125- const mockedConfig = vi . mocked ( config ) ;
126- mockedConfig . ui . experimental ! . feeOffsetting = false ;
135+ const disabledConfig = {
136+ ui : {
137+ experimental : {
138+ feeOffsetting : false ,
139+ } ,
140+ } ,
141+ } ;
127142
128143 const feeOffset = sdkAmount . fromBaseUnits ( 1000n , 6 ) ;
129144 calculateFeeOffset . mockReturnValue ( feeOffset ) ;
@@ -137,14 +152,20 @@ describe('FeeOffset', () => {
137152 'TestRoute' ,
138153 ) ;
139154
155+ // Use wrapper with disabled feeOffsetting config
156+ const DisabledWrapper = ( { children } : { children : React . ReactNode } ) => (
157+ < TestConfigContext . Provider value = { disabledConfig } >
158+ < Provider store = { store } >
159+ < ThemeProvider theme = { theme } > { children } </ ThemeProvider >
160+ </ Provider >
161+ </ TestConfigContext . Provider >
162+ ) ;
163+
140164 render ( < FeeOffset /> , {
141- wrapper : AppWrapper ( store ) ,
165+ wrapper : DisabledWrapper ,
142166 } ) ;
143167
144168 expect ( screen . queryByText ( / \+ .* U S D C / ) ) . not . toBeInTheDocument ( ) ;
145-
146- // Reset config for other tests
147- mockedConfig . ui . experimental ! . feeOffsetting = true ;
148169 } ) ;
149170
150171 it ( 'does not render when feeOffsetAmount is undefined' , async ( ) => {
0 commit comments