3
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 5 years have passed since last update.

【jest】Javascriptのテストツールjestのインストールと最小限の使用方法

Last updated at Posted at 2019-06-30

#概要
Javascriptのテストツールであるjestをインストールして最小限の使い方を理解するまで。

#インストール

$ npm -D install jest

#テストするファイル作成

sum.js
function sum(a, b) {
	return a + b;
}
module.exports = sum;

#テストコードを書く

run.test.js
const sum = require('./sum');

test('adds 1 + 2 to equal 3', () => {
	expect(sum(1, 2)).toBe(3);
});

#package.jsonを書く

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

#テスト実行

$ npm run test

#実行結果

 PASS  ./sum.test.js
  ✓ adds 1 + 2 to equal 3 (3ms)

Test Suites: 1 passed, 1 total
Tests:       1 passed, 1 total
Snapshots:   0 total
Time:        1.466s
Ran all test suites.

#Happy Hacking :sunglasses: !

3
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
3
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?