From 38c5b7bc346bdf87e92c00e2a46eeddd33283601 Mon Sep 17 00:00:00 2001 From: Kathy Luo Date: Mon, 9 Sep 2024 14:35:09 +0200 Subject: [PATCH] fix: use mocked date in EarnPoolInfoScreen test (#5942) ### Description As the title. Also fixes the following warning in the tests by updating the way we are using `MockedNavigator` in the tests. ``` Looks like you're passing an inline function for 'component' prop for the screen 'MockedScreen' (e.g. component={() => }). Passing an inline function will cause the component state to be lost on re-render and cause perf issues since it's re-created every render. You can pass the function as children to 'Screen' instead to achieve the desired behaviour. ``` ### Test plan n/a ### Related issues n/a ### Backwards compatibility Y ### Network scalability If a new NetworkId and/or Network are added in the future, the changes in this PR will: - [ ] Continue to work without code changes, OR trigger a compilation error (guaranteeing we find it when a new network is added) --- src/earn/EarnPoolInfoScreen.test.tsx | 34 ++++++++-------------------- 1 file changed, 9 insertions(+), 25 deletions(-) diff --git a/src/earn/EarnPoolInfoScreen.test.tsx b/src/earn/EarnPoolInfoScreen.test.tsx index ab74f5c781c..b36cb820f4f 100644 --- a/src/earn/EarnPoolInfoScreen.test.tsx +++ b/src/earn/EarnPoolInfoScreen.test.tsx @@ -9,7 +9,7 @@ import { Screens } from 'src/navigator/Screens' import { EarnPosition } from 'src/positions/types' import { navigateToURI } from 'src/utils/linking' import MockedNavigator from 'test/MockedNavigator' -import { createMockStore, getMockStackScreenProps } from 'test/utils' +import { createMockStore } from 'test/utils' import { mockArbUsdcTokenId, mockEarnPositions, mockTokenBalances } from 'test/values' const mockPoolTokenId = mockEarnPositions[0].dataProps.depositTokenId @@ -23,17 +23,16 @@ const store = createMockStore({ const renderEarnPoolInfoScreen = (pool: EarnPosition) => render( - ( - - )} - /> + ) describe('EarnPoolInfoScreen', () => { beforeEach(() => { jest.clearAllMocks() + jest.useFakeTimers({ + now: new Date('2024-08-15T00:00:00.000Z'), + }) }) it('renders correctly when not deposited in pool', () => { @@ -255,17 +254,7 @@ describe('EarnPoolInfoScreen', () => { it('navigate to EarnEnterAmount when Deposit button is tapped', () => { const { getByText } = render( - { - return ( - - ) - }} - /> + ) fireEvent.press(getByText('earnFlow.poolInfoScreen.deposit')) @@ -284,14 +273,9 @@ describe('EarnPoolInfoScreen', () => { const { getByText } = render( { - return ( - - ) + component={EarnPoolInfoScreen} + params={{ + pool: { ...mockEarnPositions[0], balance: '100' }, }} />