1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

【Jest】最速セットアップ

Last updated at Posted at 2020-05-11

jestをインストールし、テストファイルを作成します

yarn add jest -D
mkdir test
touch test/sample.test.js

nodeにはes6の記法を用いることができないので、
nodeでjestを実行するために、babelをトランスパイラーとして設定します。

~/babel.config.js
module.exports = {
  presets: [
    ['@babel/preset-env', { modules: false }]
  ],
  env: {
    test: {
      presets: [
        ['@babel/preset-env', { targets: { node: 'current' } }]
      ]
    }
  }
}

jestのテスト対象ファイル拡張子にjsを指定します。

~/jest.config.js
module.exports = {
  transform: {
    '^.+\\.js$': '<rootDir>/node_modules/babel-jest'
  },
  moduleFileExtensions: [
    'js'
  ]
}

あとはtestを記述し実行するだけです。

npx jest
1
1
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
1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?