LoginSignup
3
3

More than 3 years have passed since last update.

概要

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を実行するだけ。

3
3
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
3