0
0

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

TypescriptでOptional chainingを使用した箇所がJestのCoverageに反映されない場合

Posted at

現象

以下のようにOptional chainingを使用してオブジェクトを読み込んだ箇所が、

    result.userId = response?.userId;
    result.todoId = response?.todoId;
    result.title = response?.title;

テストを通しているはずなのにJestのCoverageに反映されない

------------------------|---------|----------|---------|---------|-------------------
File                    | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s 
------------------------|---------|----------|---------|---------|-------------------
All files               |   98.01 |    93.18 |   97.62 |      98 |                   
 lambda/domains         |     100 |      100 |     100 |     100 |                   
  todoUseCase.ts        |     100 |      100 |     100 |     100 | 103-105 <-消えてくれない    
略      
------------------------|---------|----------|---------|---------|-------------------

解消法

こちらのIssueに書いてある方法を試したところ解消しました

tsconfig.jsonのcompilerOptions.targetを「ES2020」に設定

tsconfig.json
{
  "compilerOptions": {
    "target": "ES2020",
  }
}
0
0
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
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?