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

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

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

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

06b9c7286903fd1062a201e1a3ac65d9?s=128

Shunta Saito

June 26, 2019
Tweet

Transcript

  1. 2.

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

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

    Jestͱ͸ Jest is a delightful JavaScript Testing Framework with a

    focus on simplicity.
 γϯϓϧ͞ʹϑΥʔΧεָ͍ͨ͠͠+BWB4DSJQU 5FTUJOH'SBNFXPSL
  3. 5.

    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. 6.

    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. 11.
  6. 12.

    ԿΛςετ͢΂͖͔ ❌ٯʹ͜Μͳςετ͸ෆཁ ˞ݸਓͷҙݟͰ͢  w ϥΠϒϥϦͷڍಈ w ͦ΋ͦ΋ϥΠϒϥϦଆͰςετΛॻ͍ͯΔ͸ͣɻ w 6*ͷςετ

    w ৔߹ ϓϩμΫτͷੑ࣭ɺ։ൃن໛ ʹ΋ΑΔ͕ɺ6* ͸ίϩίϩมΘΔͷͰɺॻ͍ͯ΋ແବʹͳΓ͕ͪ
  7. 14.

    ࿩ͨ͜͠ͱ w 4JOPO+4ͷVTF'BLF5JNFST ͱ͍͏ͷΛ࢖͏ͱɺ ೔෇ͷϞοΫ͕Ͱ͖Δɻ˞+FTUʹ΋૊ΈࠐΈͷ VTF'BLF5JNFST ͕͋Δɻ w KFTUGO Λ࢖͏ͱɺؔ਺ΛϞοΫͰ͖Δɻ˞Πϕϯ

    τϋϯυϥ ྫPO$MJDL ͷςετͱ͔Ͱ΋࢖͑ͯศར w KFTUNPDL Λ࢖͏ͱɺಛఆͷϞδϡʔϧΛϞοΫ Ͱ͖Δɻ˞@@NPDLT@@σΟϨΫτϦʹϑΝΠϧΛஔ ͘͜ͱͰࣗಈͰϞοΫ͢Δ࢓૊Έ΋͋Γ·͢ɻ
  8. 17.

    ͓·͚ w KFTUTQZ0O Λ࢖͏ͱɺϝιουݺͼग़͠ΛϞοΫ Ͱ͖Δɻ ϞοΫݩͷݺͼग़͠Λ๷͙৔߹͸ KFTUTQZ0O NPDL*NQMFNFOUBUJPO Λ࢖͏ɻ 

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