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

JestとWallaby.jsで始める楽しいJavaScript testing

JestとWallaby.jsで始める楽しいJavaScript testing

JestとWallaby.jsを使ってモックを含むテストを書く方法を共有します。

https://github.com/subuta/play-with-jest

Shunta Saito

June 26, 2019
Tweet

More Decks by Shunta Saito

Other Decks in Programming

Transcript

  1. ࣗݾ঺հ • ໊લ: ੪౻ॣଠ (@subuta) • JavaScriptपΓͷ΋ͷ͕޷͖Ͱ ͢ɻ࠷ۙ͸͓࢓ࣄͰ΋ Node.js(Koa +

    Next.js)Λ࢖͑ͯ ͯϋοϐʔͰ͢ɻ • React͕ओʹ޷͖Ͱ͕͢ɺVue.js ΋Angular.js΋ᅂΉఔ౓ʹ͸ ৮ͬͯ·͢ɻ༻్ʹԠͨ͡ద੾ ͳ΋ͷΛબͿͷ͕ྑͦ͞͏ɻ
  2. Jestͱ͸ Jest is a delightful JavaScript Testing Framework with a

    focus on simplicity.
 γϯϓϧ͞ʹϑΥʔΧεָ͍ͨ͠͠+BWB4DSJQU 5FTUJOH'SBNFXPSL
  3. Wallaby.jsͱ͸ Wallaby.js runs your JavaScript tests immediately as you type

    and displays execution results in your code editor. It also provides beautiful test and code coverage reports updated in realtime.
  4. Wallaby.jsͱ͸ Wallaby.js runs your JavaScript tests immediately as you type

    and displays execution results in your code editor. It also provides beautiful test and code coverage reports updated in realtime.
 
 8BMMBCZKT͸͋ͳͨͷςετίʔυΛλΠϐϯάʹԠ ࣮ͯ͡ߦ͠ɺ࣮ߦ݁ՌΛΤσΟλ্ʹදࣔ͠·͢ɻ
 ·ͨϦΞϧλΠϜͰͷςετͷ࣮ߦ݁Ռ͓Αͼίʔυ ΧόϨοδͷϨϙʔτදࣔ΋ߦ͍·͢ɻ
  5. ԿΛςετ͢΂͖͔ ❌ٯʹ͜Μͳςετ͸ෆཁ ˞ݸਓͷҙݟͰ͢  w ϥΠϒϥϦͷڍಈ w ͦ΋ͦ΋ϥΠϒϥϦଆͰςετΛॻ͍ͯΔ͸ͣɻ w 6*ͷςετ

    w ৔߹ ϓϩμΫτͷੑ࣭ɺ։ൃن໛ ʹ΋ΑΔ͕ɺ6* ͸ίϩίϩมΘΔͷͰɺॻ͍ͯ΋ແବʹͳΓ͕ͪ
  6. ࿩ͨ͜͠ͱ w 4JOPO+4ͷVTF'BLF5JNFST ͱ͍͏ͷΛ࢖͏ͱɺ ೔෇ͷϞοΫ͕Ͱ͖Δɻ˞+FTUʹ΋૊ΈࠐΈͷ VTF'BLF5JNFST ͕͋Δɻ w KFTUGO Λ࢖͏ͱɺؔ਺ΛϞοΫͰ͖Δɻ˞Πϕϯ

    τϋϯυϥ ྫPO$MJDL ͷςετͱ͔Ͱ΋࢖͑ͯศར w KFTUNPDL Λ࢖͏ͱɺಛఆͷϞδϡʔϧΛϞοΫ Ͱ͖Δɻ˞@@NPDLT@@σΟϨΫτϦʹϑΝΠϧΛஔ ͘͜ͱͰࣗಈͰϞοΫ͢Δ࢓૊Έ΋͋Γ·͢ɻ
  7. ͓·͚ w KFTUTQZ0O Λ࢖͏ͱɺϝιουݺͼग़͠ΛϞοΫ Ͱ͖Δɻ ϞοΫݩͷݺͼग़͠Λ๷͙৔߹͸ KFTUTQZ0O NPDL*NQMFNFOUBUJPO Λ࢖͏ɻ 

    w +FTUʹ͸4OBQTIPU5FTUJOHͱ͍͏6*ͷςετ޲͚ʹ ར༻Ͱ͖Δػೳ͕͋Γ·͢ɻ w &&ςετ ϒϥ΢βʹΑΔࣗಈςετ Λߦ͏৔߹͸ɺ $ZQSFTTͱ͍͏πʔϧ΋͋Γ·͢ɻ Կ͔Χοί͍͍ ΍ͭ