测试库总是很有趣。我正在我的NextJS项目中使用next-i18next
。我们正在使用带有命名空间的useTranslation
钩子。
当我运行测试时,会出现以下警告:
console.warn react-i18next:您需要通过使用initReactI18next传递i18next实例
> 33 | const { t } = useTranslation(['common', 'account']);
| ^
我尝试了react-i18next测试例子的设置,但没有成功。我还尝试了这个建议。
此外,我还尝试了模拟useTranslation
,但也没有成功。
有没有更简单的解决方案来避免这个警告?就测试而言,测试已经通过了...
test('feature displays error', async () => {
const { findByTestId, findByRole } = render(
<I18nextProvider i18n={i18n}>
<InviteCollectEmails onSubmit={jest.fn()} />
</I18nextProvider>,
{
query: {
orgId: 666,
},
}
);
const submitBtn = await findByRole('button', {
name: 'account:organization.invite.copyLink',
});
fireEvent.click(submitBtn);
await findByTestId('loader');
const alert = await findByRole('alert');
within(alert).getByText('failed attempt');
});
最后,是否有办法让翻译后的纯文本成为结果,而不是带命名空间的:
account:account:organization.invite.copyLink
?