Upgrade to Pro — share decks privately, control downloads, hide ads and more …

TypeScriptでDIしてみた

Sponsored · SiteGround - Reliable hosting with speed, security, and support you can count on.

 TypeScriptでDIしてみた

Avatar for Ryohei Hisamitsu

Ryohei Hisamitsu

January 16, 2021

More Decks by Ryohei Hisamitsu

Other Decks in Technology

Transcript

  1. 何が嬉しいの? • 単体テストがしやすくなる! class Service { private repository; constructor() {

    this.repository = new Repository(); } find() { // ... this.repository.find(); return; } } よくあるテストしにくい例 テストしたいのはService層のロジック Repository(DB)のテストも含まれてしまう  ・テスト失敗した時の切り分けが面倒  ・実行時間がかかる DI→テスト側からモックを注入できる!