Skip to content

Advanced Level 3

takahito.miyamoto edited this page Feb 5, 2020 · 6 revisions

上級 Lv. 3

問題

LWC のテストコードを実行してみましょう。Apex コードと違い、JacaScript コードにはテストカバレッジの制約はありませんが、品質のよいコードを書くためにテストコードは重要です。

Hints

Test Lightning Web Components

解答

sfdx-lwc-jest のインストール

npm install --save-dev --save-exact @salesforce/sfdx-lwc-jest

npm script の追加

package.json の scripts に以下のコードを追加しましょう。

{
  ...
  "scripts": {
    ...
    "test:unit:jest": "sfdx-lwc-jest",
    "test:unit:watch": "sfdx-lwc-jest --watch",
    "test:unit:debug": "sfdx-lwc-jest --debug",
    ...
  },
  ...

テスト実行

npm run test:unit:jest

テスト実行結果の確認

# 例
Test Suites: 7 failed, 60 passed, 67 total
Tests:       12 failed, 140 passed, 152 total

エラーを修正する

🚧 更新中です 🚧


👈 前に戻る | 次に進む 👉

Clone this wiki locally