3
2

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を簡単に動かしてみた

Last updated at Posted at 2015-04-02

JestはFacebookがReact.jsを使ったアプリケーション開発に使っているフロントエンドのテストフレームワーク。

とりあえず動かしてみたときの手順メモ。

$ mkdir jest_test; cd jest_test; git init
$ npm init # test => jest
$ git add .; git cm -m "Initialize package.json"
$ npm install --save-dev jest-cli
$ git add .; git cm -m "Add jest-cli to node_modules"

ここまでで準備完了。次に実行ファイルを書く。FacebookのJest公式トップにある例そのまま。

sum.js

function sum(value1, value2) {
  return value1 + value2;
}

module.exports = sum;

次にテストスクリプト。

__tests__/sum-test.js

jest.dontMock('../sum');

describe('sum', function() {
  it('adds 1 + 2 to equal 3', function() {
    var sum = require('../sum');
    expect(sum(1, 2)).toBe(3);
  });
});

テストを実行してみる。

$ npm test

> jest_test@1.0.0 test /Users/yusukenozoe/Desktop/jest_test
> jest

Using Jest CLI v0.4.0
 PASS  __tests__/sum-test.js (0.01s)
1 test passed (1 total)
Run time: 0.217s

かなり簡単に導入できるということがわかった。

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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?