小编Tve*_*edt的帖子

使用 nextjs 和 next-intl 对组件进行 Jest 单元测试

我正在尝试使用 next-intl 为我的 nextjs 组件创建单元测试。

我的组件:

import Head from "next/head";
import { useTranslations } from "next-intl";

export default function Home() {
  const t = useTranslations("HomePage");

  return (
    <div>
      <Head>
        <title>My title goes here</title>
        <meta name="description" content="Generated by create next app" />
        <link rel="icon" href="/favicon.ico" />
      </Head>
      <h1>{t("welcome")}</h1>
    </div>
  );
}

// Get localized messages
export function getStaticProps({ locale }) {
  return {
    props: {
      messages: require(`locales/${locale}.json`),
    },
  };
}
Run Code Online (Sandbox Code Playgroud)

如何在以下行中创建单元测试:

 import Home from '../pages/index'
 
 describe('Home', () => {
   it('renders a …
Run Code Online (Sandbox Code Playgroud)

unit-testing internationalization reactjs jestjs next.js

9
推荐指数
0
解决办法
1982
查看次数