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

TypeScriptでDIしてみた

Sponsored · Your Podcast. Everywhere. Effortlessly. Share. Educate. Inspire. Entertain. You do you. We'll handle the rest.

 TypeScriptでDIしてみた

Avatar for Ryohei Hisamitsu

Ryohei Hisamitsu

January 16, 2021
Tweet

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→テスト側からモックを注入できる!