Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Sign up for free
Menu
Search
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Pricing
Search
Sign in
Sign up for free
Mocha
Search
Kaneko Takeshi
December 21, 2017
Technology
59
0
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
Mocha
Kaneko Takeshi
December 21, 2017
More Decks by Kaneko Takeshi
See All by Kaneko Takeshi
オープンソースライセンスについて勉強する定期
tkckaneko
0
46
Eye Tracking on the Browser
tkckaneko
0
99
IEEE754を完全に理解した
tkckaneko
1
88
CSSのトレンドをみんなで見よう -2021年-
tkckaneko
0
100
多分これが一番早いと思います
tkckaneko
0
31
暗黒面の話
tkckaneko
0
31
CSR / SSR / SSG / JAMstack
tkckaneko
0
79
BOLT
tkckaneko
0
41
CSS Logical Properties and Values
tkckaneko
0
60
Other Decks in Technology
See All in Technology
Geolonia の開発現場における AIの活用について
miya0001
0
100
LTのテーマ どうきめてる?〜5つの型と私のやり方〜
yama3133
1
110
負債のメタファと2026年 / Debt Metaphor in Agentic Engineering Age 202609 Edition
twada
PRO
5
2.7k
事業課題から技術的負債に向き合う
sansantech
PRO
2
1.8k
Claude Code本って、 読む必要あるの?
oikon48
2
460
フルカイテン株式会社 エンジニア向け採用資料
fullkaiten
0
12k
TinyGo 開発サイクルを高速化する:Go で作るエミュレータ入門
zozotech
PRO
1
740
2026/09/10 Spring Bootから Jakarta EE/MicroProfileへの移行
megascus
0
370
開発投資の期待値を上げるプロダクトロードマップづくり ~プロダクトエンジニアが越境して事業を伸ばす~
kekekenta
1
180
ソフトウェアDNAとクラウドエージェントのススメ
cloudace
0
110
AI に書かせたその API、 “信頼” できますか?
nagix
0
110
10Xに技術的負債をもたらした「2つの境界の歪み」その構造と解消への営み
10xinc
0
1.9k
Featured
See All Featured
Evolving SEO for Evolving Search Engines
ryanjones
0
290
The browser strikes back
jonoalderson
0
1.7k
Facilitating Awesome Meetings
lara
57
7.1k
Joys of Absence: A Defence of Solitary Play
codingconduct
1
520
Why Mistakes Are the Best Teachers: Turning Failure into a Pathway for Growth
auna
0
280
Designing for Timeless Needs
cassininazir
1
480
How to audit for AI Accessibility on your Front & Back End
davetheseo
0
540
The Success of Rails: Ensuring Growth for the Next 100 Years
eileencodes
47
8.3k
How to build a perfect <img>
jonoalderson
1
6k
The Illustrated Children's Guide to Kubernetes
chrisshort
51
53k
End of SEO as We Know It (SMX Advanced Version)
ipullrank
3
4.4k
Raft: Consensus for Rubyists
vanstee
142
7.7k
Transcript
Mocha
None
テストツールの話をします
Mocha - JavaScriptのユニットテストフレームワーク - node.jsやブラウザから実行できる - IDE(WebStormなど)からも実行できる
Mocha 設定もコードも簡単にできます。 chaiやshould.jsなどのアサーションライブラリを使えば、 いろいろな書き方もできますが、今回は話しません。
準備 $ yarn add -D mocha
準備 package.json “scripts”: { “test”: “mocha” }
準備 $ yarn test
簡単な例 var assert = require('assert'); describe('Array', function() { describe('#indexOf()', function()
{ it('should return -1 when the value is not present', function() { assert.equal([1,2,3].indexOf(4), -1); }); }); });
簡単な例 $ mocha "test/test01.js" Array #indexOf() ✓ should return -1
when the value is not present 1 passing (8ms) ✨ Done in 0.50s.
非同期の例 const assert = require('assert'); function asyncAdd(a, b) { return
new Promise((resolve) => { resolve(a+b); }); }; describe('async test', () => { it('Promise', (done) => { let result = 0; asyncAdd(2, 3).then((result) => { assert(result === 9); }).then(done, done); }) });
非同期の例 $ mocha "test/test02.js" async test ✓ Promise 1 passing
(12ms) ✨ Done in 0.46s.
ブラウザでも動きます
ブラウザの例 <html> <head> <meta charset="utf-8"> <title>Mocha Tests</title> <link href="https://cdn.rawgit.com/mochajs/mocha/2.2.5/mocha.css" rel="stylesheet"
/> </head> <body> <div id="mocha"></div> <script src="https://cdn.rawgit.com/jquery/jquery/2.1.4/dist/jquery.min.js"></script> <script src="https://cdn.rawgit.com/Automattic/expect.js/0.3.1/index.js"></script> <script src="https://cdn.rawgit.com/mochajs/mocha/2.2.5/mocha.js"></script> <script>mocha.setup('bdd')</script>
ブラウザの例
テストの結果を 変えることもできます
reporter $ yarn test --reporter json
reporter $ mocha "test/test01.js" "--reporter" "json" { "stats": { "tests":
[ { } ], "pending": [], "failures": [], ・・・ ✨ Done in 0.45s.
独自のreporter 作り方について詳しくはこちら https://github.com/mochajs/mocha/wiki/Third-party-reporters
独自のreporter $ yarn test --reporter ne
独自のreporter
おしまい いつか公開します。。。