Jestjs next-i18next Jest测试与UseTransation

Jestjs next-i18next Jest测试与UseTransation,jestjs,next.js,react-i18next,next-i18next,Jestjs,Next.js,React I18next,Next I18next,测试libs…总是很有趣。我正在NextJS项目中使用next-i18next。我们正在使用useTranslationhook和名称空间 当我运行测试时,会出现一个警告: console.warn react-i18next::需要使用initReactI18next传入i18next实例 我已尝试从中进行设置,但未成功。我试过了 以及试图模仿useTranslation,但没有成功 是否有更直接的解决方案来避免此警告?测试通过了FWIW test('feature displays err

测试libs…总是很有趣。我正在NextJS项目中使用
next-i18next
。我们正在使用
useTranslation
hook和名称空间

当我运行测试时,会出现一个警告:

console.warn react-i18next::需要使用initReactI18next传入i18next实例


我已尝试从中进行设置,但未成功。我试过了

以及试图模仿
useTranslation
,但没有成功

是否有更直接的解决方案来避免此警告?测试通过了FWIW

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');
  });
test('feature displays error',async()=>{
const{findByTestId,findByRole}=render(
,
{
查询:{
来源:666,
},
}
);
const submitBtn=wait findByRole('按钮'{
名称:'帐户:organization.invite.copyLink',
});
fireEvent.单击(提交);
等待findByTestId('loader');
const alert=等待findByRole(“警报”);
在(alert.getByText('尝试失败')中;
});

最后,是否有一种方法可以将翻译后的纯文本作为结果,而不是名称空间:
帐户:帐户:组织。invite.copyLink

在descripe块之前或beforeach()中使用以下代码片段模拟需要的内容

jest.mock("react-i18next", () => ({
    useTranslation: () => ({ t: key => key }),
}));

希望这有帮助。和平。

在descripe块之前或beforeach()中使用以下代码段模拟需要的代码

jest.mock("react-i18next", () => ({
    useTranslation: () => ({ t: key => key }),
}));

希望这有帮助。和平。

你找到解决方案了吗?不……我可能会调查你找到解决方案了吗?不……我可能会调查,把它放在descripe()博客之前很有效。对我来说,把它放在descripe()博客之前很有效。