Help us understand the problem. What is going on with this article?

Next.jsのテスト【Jest編】

概要

ReactのフレームワークNext.jsで開発することになったので、勉強したことをメモ的に投稿していこうと思います。

Next.js 公式ページ

Jest / TypeScript Deep Dive 日本語版

テストの準備

1. Jestのインストール

$ yarn add --dev jest babel-jest babel-core babel-preset-env babel-preset-react @types/jest

2. Jestの設定

jest.config.js
module.exports = {
    roots: ["<rootDir>"],
    transform: { "^.+\\.tsx?$": "babel-jest" },
    testPathIgnorePatterns: [
        "<rootDir>.next/",
        "<rootDir>/node_modules/"
    ],
    moduleFileExtensions: [
        "ts", "tsx", "js", "jsx", "json", "node"
    ],
    testMatch: ["**/__tests__/**/*.test.(ts|tsx|js)"]
}

3. テストの実行

package.json
{
  "test": "jest"
}

ざっくりまとめ

1. 必要なパッケージをインストール

2. jest.config.jsをプロジェクトのルートに追加し設定

3. package.jsonにコマンドを追加

あとは__tests__ディレクトリー を作成しその直下にテストファイル〇〇.test.tsなど作成し、jestを実行するだけ。

Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
Comments
No comments
Sign up for free and join this conversation.
If you already have a Qiita account
Why do not you register as a user and use Qiita more conveniently?
You need to log in to use this function. Qiita can be used more conveniently after logging in.
You seem to be reading articles frequently this month. Qiita can be used more conveniently after logging in.
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
ユーザーは見つかりませんでした