首页 > 解决方案 > 如何在 Jest 中从 react-i18next 模拟 Trans 组件

问题描述

我试图在 Jest 中从 react-i18next 模拟这个 Trans 组件:

<Trans
      i18nKey="orderCards.business.paragraph"
      components={{
        p: <p />,
        strong: <strong />,
        Link: (
          <BusinessAccountLink
            to="/"
            data-testid="business-account-link"
          />
        ),
      }}
    />

It returns this: <p>Text <strong>Bold Text <Link>Click Me</Link></strong></p>
This link is a Link component from react-router-dom

我如何模拟这个组件,以便我可以测试单击时链接是否有效。

标签: reactjsjestjsreact-i18next

解决方案


推荐阅读