LoginSignup
0
1

More than 3 years have passed since last update.

Hello ts-jest

Posted at

ディレクトリ作成

$ mkdir hello
$ cd hello

初期化

$ npm init

目をつむって全部エンターを押す

いろいろ入れたり初期化したり

$ npm i -D jest typescript
$ npm i -D ts-jest @types/jest
$ npx ts-jest config:init

テストファイル作る

$ mkdir __tests__
$ touch __tests__/hello.test.ts

テスト書く

hello.test.tsに以下を追加

import hello from "../src/hello"

test('hello', () => {
    expect(hello()).toBe('Hello');
})

テスト対象となるファイルを作る

$ mkdir src
$ touch src/hello.ts

コードを書く

hello.tsに以下を追加

export default () => 'Hello'

package.jsonをいじる

{
  "name": "hello",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "scripts": {
    "test": "jest"
  },
  "author": "",
  "license": "ISC",
  "devDependencies": {
    "@types/jest": "^24.9.0",
    "jest": "^25.1.0",
    "ts-jest": "^25.0.0",
    "typescript": "^3.7.5"
  }
}

Ready perfectly

準備は完全に整った。あとは

$ npm t

を実行するだけ

余談

Ready perfectlyというのは英語的にかなりおかしいそうです。正しくは、Absolutely prepared。もしくはAbsolutely ready to goだそうです。わざと間違った表現を使用している可能性もありますが・・・。面白いから好きですけどね!!

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