You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'd like to mock next-intluseTranslations function/hook so I could test my components without having to ever guess what language it's being tested. For that, I want the component to render it with its keys translations instead of its value.
For example, for a server component, the component below:
It will just render the key 'wonderful' in my jest test because I don't need / want to check its value - but i do want to test if it's being rendered!
jest.mock('next-intl/server',()=>({
...jest.requireActual('next-intl/server'),getTranslations: jest.fn().mockReturnValue((key: string)=>key),}))describe('<SomeSSRComponent />',()=>{test('renders with proper text',async()=>{render(awaitSomeSSRComponent())consttitle=screen.getByText('wonderful',)expect(title).toBeInTheDocument()})})
...and then this would just pass.
My question here is to do the same with next-int and useTranslations hook. If I try to mock it just like the function getTranslations above, nothing happens.
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
Hi guys!
I'd like to mock
next-intl
useTranslations
function/hook so I could test my components without having to ever guess what language it's being tested. For that, I want the component to render it with its keys translations instead of its value.For example, for a server component, the component below:
It will just render the key
'wonderful'
in my jest test because I don't need / want to check its value - but i do want to test if it's being rendered!...and then this would just pass.
My question here is to do the same with
next-int
anduseTranslations
hook. If I try to mock it just like the functiongetTranslations
above, nothing happens.Do you know how I could get the same result as getTranslations above?
Thank you in advance!
Beta Was this translation helpful? Give feedback.
All reactions