Hello ts-jest
2429 ワード
ディレクトリ作成
$ mkdir hello
$ cd hello
初期化
$ npm init
$ 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
テスト書く
$ 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
コードを書く
$ 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
{
"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"
}
}
準備は完全に整った。あとは
$ npm t
を実行するだけ
余談
Ready perfectlyというのは英語的にかなりおかしいそうです。正しくは、Absolutely prepared。もしくはAbsolutely ready to goだそうです。わざと間違った表現を使用している可能性もありますが・・・。面白いから好きですけどね!!
Author And Source
この問題について(Hello ts-jest), 我々は、より多くの情報をここで見つけました https://qiita.com/Boccochan/items/4ea392eae98bbf82a15c著者帰属:元の著者の情報は、元のURLに含まれています。著作権は原作者に属する。
Content is automatically searched and collected through network algorithms . If there is a violation . Please contact us . We will adjust (correct author information ,or delete content ) as soon as possible .