Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
Mocha
Search
Sponsored
·
Your Podcast. Everywhere. Effortlessly.
Share. Educate. Inspire. Entertain. You do you. We'll handle the rest.
→
Kaneko Takeshi
December 21, 2017
Technology
49
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
44
Eye Tracking on the Browser
tkckaneko
0
99
IEEE754を完全に理解した
tkckaneko
1
85
CSSのトレンドをみんなで見よう -2021年-
tkckaneko
0
100
多分これが一番早いと思います
tkckaneko
0
31
暗黒面の話
tkckaneko
0
31
CSR / SSR / SSG / JAMstack
tkckaneko
0
79
BOLT
tkckaneko
0
40
CSS Logical Properties and Values
tkckaneko
0
55
Other Decks in Technology
See All in Technology
Retriever と Reranker、結局どうする?
kazuaki
2
670
LLMリーダーボードアップデートに向けたAgentic Math_SWEのトレースについて
nejumi
0
210
【CEDEC2026】次世代デジタルカードゲームのサーバー設計と運用 〜『Shadowverse: Worlds Beyond』の舞台裏~
cygames
PRO
0
880
Eight Engineering Unit 紹介資料
sansan33
PRO
3
8.1k
新しい SLO が良い感じにハマっている話
z63d
4
2.1k
トヨタ⽣産⽅式(TPS)⼊⾨
recruitengineers
PRO
1
450
初めてのGitHub Actions / GitHub Actions at First
tooppoo
0
140
Software Supply Chain Attackからクラウド環境を守るためにできること
lhazy
2
120
[ChatGPT Work LT]事務作業が苦手な人のための バックオフィスの「半」自動化
chimaki_iot
0
200
Data Hubグループ 紹介資料
sansan33
PRO
0
3.1k
[MIRU26] Open-Vocabulary Intention-Guided Object Detection in Diverse Scenes
keio_smilab
PRO
0
140
モノリス Rails でも日中に rails db:migrate を走らせたい! / Daytime rails db:migrate on Monolithic Rails!
euglena1215
3
470
Featured
See All Featured
Joys of Absence: A Defence of Solitary Play
codingconduct
1
420
The Myth of the Modular Monolith - Day 2 Keynote - Rails World 2024
eileencodes
28
3.6k
B2B Lead Gen: Tactics, Traps & Triumph
marketingsoph
0
190
Building Adaptive Systems
keathley
44
3.2k
The Hidden Cost of Media on the Web [PixelPalooza 2025]
tammyeverts
2
420
Deep Space Network (abreviated)
tonyrice
0
250
From π to Pie charts
rasagy
0
250
Cheating the UX When There Is Nothing More to Optimize - PixelPioneers
stephaniewalter
287
14k
Optimizing for Happiness
mojombo
378
71k
How Fast Is Fast Enough? [PerfNow 2025]
tammyeverts
3
700
Lightning talk: Run Django tests with GitHub Actions
sabderemane
0
230
The Straight Up "How To Draw Better" Workshop
denniskardys
239
140k
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
おしまい いつか公開します。。。