diff --git a/app/mobile/test/Profile.test.js b/app/mobile/test/Profile.test.js index 70cc2eac..cfb43084 100644 --- a/app/mobile/test/Profile.test.js +++ b/app/mobile/test/Profile.test.js @@ -6,10 +6,15 @@ import { ProfileContextProvider, ProfileContext } from 'context/ProfileContext'; import * as fetchUtil from 'api/fetchUtil'; function ProfileView() { + const [renderCount, setRenderCount] = useState(0); const profile = useContext(ProfileContext); + useEffect(() => { + setRenderCount(renderCount + 1); + }, [profile.state]); + return ( - + { profile.state.identity?.guid } { profile.state.identity?.handle } { profile.state.identity?.name } @@ -155,6 +160,20 @@ test('testing', async () => { expect(screen.getByTestId('name').props.children).toBe("vesper"); }); + const renderCount = screen.getByTestId('profile').props.renderCount; +console.log("RENDER COUNT:", renderCount); + + await act(async () => { + identity = { name: 'renderer' }; + const profile = screen.getByTestId('profile').props.profile; + await profile.actions.setRevision(2048); + }); + +console.log(renderCount); + + await act(async () => { + expect(screen.getByTestId('profile').props.renderCount).toBe(renderCount + 1); + }); }); diff --git a/net/web/test/Profile.test.js b/net/web/test/Profile.test.js index 5a22fb5b..97d25a5a 100644 --- a/net/web/test/Profile.test.js +++ b/net/web/test/Profile.test.js @@ -5,11 +5,17 @@ import * as fetchUtil from 'api/fetchUtil'; let profileContext = null; function ProfileView() { + const [renderCount, setRenderCount] = useState(0); const profile = useContext(ProfileContext); profileContext = profile; + useEffect(() => { + setRenderCount(renderCount + 1); + }, [profile.state]); + return (
+ { renderCount } { profile.state.identity?.guid } { profile.state.identity?.handle } { profile.state.identity?.name } @@ -84,6 +90,19 @@ test('testing', async () => { expect(screen.getByTestId('name').textContent).toBe("tester"); }); + const count = screen.getByTestId('count').textContent; + + await act(async () => { + identity = { name: 'renderer' }; + await profileContext.actions.setRevision(3); + }); + + await waitFor(async () => { + const renderCount = parseInt(screen.getByTestId('count').textContent); + const nextCount = parseInt(count) + 1; + expect(nextCount).toBe(renderCount); + }); + await act(async () => { await profileContext.actions.clearToken(); }); @@ -92,7 +111,6 @@ test('testing', async () => { expect(screen.getByTestId('name').textContent).toBe(""); }); - });