0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

【Jest】「Cannot find name 'jest'.」の解決方法

0
Posted at

はじめに

Jestでテストを書こうとしたら、エラーが出てdescribe, it, expectなどの関数が使えませんでした。

問題

Cannot find name 'jest'.

解決方法

tsconfig.app.jsonにjestの設定を加える。

{
  "compilerOptions": {
    "tsBuildInfoFile": "./node_modules/.tmp/tsconfig.app.tsbuildinfo",
    "target": "es2023",
    "lib": ["ES2023", "DOM"],
    "module": "esnext",
-   "types": ["vite/client"],
+   "types": ["vite/client", "jest", "@testing-library/jest-dom"],
    "skipLibCheck": true,

    /* Bundler mode */
    "moduleResolution": "bundler",
    "allowImportingTsExtensions": true,
    "verbatimModuleSyntax": true,
    "moduleDetection": "force",
    "noEmit": true,
    "jsx": "react-jsx",

    /* Linting */
    "noUnusedLocals": true,
    "noUnusedParameters": true,
    "erasableSyntaxOnly": true,
    "noFallthroughCasesInSwitch": true
  },
  "include": ["src"]
}

おわりに

過去にも同じことがあって、その時はなんかの記事を見て解決しました。
今回はすぐに見つからなかったので、過去の自分が作ったリポジトリを見返してたら解決できました。

自分の記事やコードに自分自身が救われることも最近結構あるので、記録を残すのは大事ですね。

0
0
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
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?